From 5818316e658dcbd6f4e9b99528f56e7ee46d183f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=88=98=ED=98=84?= Date: Thu, 26 Jun 2025 09:31:26 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=EC=A1=B0=EC=82=AC=EC=9B=90=20=ED=98=84?= =?UTF-8?q?=ED=99=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapters/web/AdminUpdatePostController.java | 3 --- .../web/model/ResearchersVisitDetailReqVO.java | 7 ++++--- .../resources/mappers/researcher/ResearcherMapper.xml | 11 +++++++++-- .../main/resources/templates/researcher/detail.html | 8 ++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/admin/src/main/java/app/module/admin/usecase/admin/saveAdmin/adapters/web/AdminUpdatePostController.java b/admin/src/main/java/app/module/admin/usecase/admin/saveAdmin/adapters/web/AdminUpdatePostController.java index b2d154af..b3289ea4 100644 --- a/admin/src/main/java/app/module/admin/usecase/admin/saveAdmin/adapters/web/AdminUpdatePostController.java +++ b/admin/src/main/java/app/module/admin/usecase/admin/saveAdmin/adapters/web/AdminUpdatePostController.java @@ -27,10 +27,7 @@ import java.util.stream.Collectors; class AdminUpdatePostController { private final AdminUpdateValidator adminUpdateValidator; - private final RoleListPortIn roleListPortIn; - private final UICodeListPortIn uiCodeListPortIn; private final SaveAdminPortIn saveAdminPortIn; - private final MessageUtil messageUtil; @PostMapping(path = "/api/settings/admin/update") ResponseEntity operate( @RequestBody AdminUpdateBindingVO bindingVO, BindingResult bindingResult) { diff --git a/admin/src/main/java/app/module/admin/usecase/researcher/adpaters/web/model/ResearchersVisitDetailReqVO.java b/admin/src/main/java/app/module/admin/usecase/researcher/adpaters/web/model/ResearchersVisitDetailReqVO.java index 0c411ee9..0aef8900 100644 --- a/admin/src/main/java/app/module/admin/usecase/researcher/adpaters/web/model/ResearchersVisitDetailReqVO.java +++ b/admin/src/main/java/app/module/admin/usecase/researcher/adpaters/web/model/ResearchersVisitDetailReqVO.java @@ -5,13 +5,14 @@ import app.module.core.config.adapters.persistence.component.AuditCommand; import lombok.Getter; import lombok.Setter; +import java.time.LocalDate; import java.time.LocalDateTime; @Getter @Setter -public class ResearchersVisitDetailReqVO { - private String id; - private String visitDate; +public class ResearchersVisitDetailReqVO extends AuditCommand { + private Integer id; + private LocalDate visitDate; private ManagementType managementType; private String content; private String isGiftSent; diff --git a/admin/src/main/resources/mappers/researcher/ResearcherMapper.xml b/admin/src/main/resources/mappers/researcher/ResearcherMapper.xml index 15751c66..38a44745 100644 --- a/admin/src/main/resources/mappers/researcher/ResearcherMapper.xml +++ b/admin/src/main/resources/mappers/researcher/ResearcherMapper.xml @@ -225,8 +225,15 @@ set visit_date = #{visitDate}, content = #{content}, management_type = #{managementType}, - is_gift_sent = #{isGiftSent}, - + + + is_gift_sent = true, + + + is_gift_sent = false, + + + where id = #{id} diff --git a/admin/src/main/resources/templates/researcher/detail.html b/admin/src/main/resources/templates/researcher/detail.html index c920931a..74a065ff 100644 --- a/admin/src/main/resources/templates/researcher/detail.html +++ b/admin/src/main/resources/templates/researcher/detail.html @@ -5,6 +5,14 @@
+ + + + + + + + From fcc1b868b710fb6534d594256d55f08a47a50e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=88=98=ED=98=84?= Date: Thu, 26 Jun 2025 10:31:11 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=EC=A1=B0=EC=82=AC=EC=9B=90=20=ED=98=84?= =?UTF-8?q?=ED=99=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/security/AdminAuthSuccessEvent.java | 6 +++--- .../adapters/persistence/UpdateNoticeDao.java | 1 - .../loggedinuser/save/ports/LoggedInUserSavePortIn.java | 8 -------- .../loggedinuser/save/ports/LoggedInUserSavePortOut.java | 8 -------- .../main/resources/mappers/notice/UpdateNoticeMapper.xml | 1 + .../save/adapter/persistence/LoggedInUserSaveDao.java | 6 +++--- .../save/adapter/persistence/LoggedInUserSaveMapper.java | 2 +- .../loggedinuser/save/ports/LoggedInUserSavePortIn.java | 8 ++++++++ .../loggedinuser/save/ports/LoggedInUserSavePortOut.java | 8 ++++++++ .../save/ports/application/LoggedInUserSaveService.java | 8 ++++---- .../ports/application/domain/LoggedInUserIdSaveCmd.java | 8 ++------ .../ports/application/domain/LoggedInUserSaveCmd.java | 9 +++------ .../uicode/view/adapters/persistence/UICodeViewDao.java | 1 - .../mappers/loggedinuser/LoggedInUserSaveMapper.xml | 2 +- 14 files changed, 34 insertions(+), 42 deletions(-) delete mode 100644 admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java delete mode 100644 admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java rename {admin/src/main/java/app/module/admin => core/src/main/java/app/module/core}/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveDao.java (73%) rename {admin/src/main/java/app/module/admin => core/src/main/java/app/module/core}/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveMapper.java (78%) create mode 100644 core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java create mode 100644 core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java rename {admin/src/main/java/app/module/admin => core/src/main/java/app/module/core}/usecase/loggedinuser/save/ports/application/LoggedInUserSaveService.java (53%) rename {admin/src/main/java/app/module/admin => core/src/main/java/app/module/core}/usecase/loggedinuser/save/ports/application/domain/LoggedInUserIdSaveCmd.java (50%) rename {admin/src/main/java/app/module/admin => core/src/main/java/app/module/core}/usecase/loggedinuser/save/ports/application/domain/LoggedInUserSaveCmd.java (54%) rename {admin => core}/src/main/resources/mappers/loggedinuser/LoggedInUserSaveMapper.xml (89%) diff --git a/admin/src/main/java/app/module/admin/config/application/security/AdminAuthSuccessEvent.java b/admin/src/main/java/app/module/admin/config/application/security/AdminAuthSuccessEvent.java index c308fcdb..61c61a2b 100644 --- a/admin/src/main/java/app/module/admin/config/application/security/AdminAuthSuccessEvent.java +++ b/admin/src/main/java/app/module/admin/config/application/security/AdminAuthSuccessEvent.java @@ -1,8 +1,8 @@ package app.module.admin.config.application.security; -import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortIn; -import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserIdSaveCmd; -import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; +import app.module.core.usecase.loggedinuser.save.ports.LoggedInUserSavePortIn; +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserIdSaveCmd; +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; import app.module.core.config.application.enums.AppType; import app.module.core.config.application.util.CommonUtil; import app.module.core.config.application.util.MessageUtil; diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java index f5276435..e4ed8ee0 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java @@ -21,7 +21,6 @@ class UpdateNoticeDao implements UpdateNoticePortOut { @Override public void operate(UpdateNoticeCmd command) { mapper.updateNotice( - new UpdateNoticeDto( command.getId(), command.getTitle(), diff --git a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java b/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java deleted file mode 100644 index d410403c..00000000 --- a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.module.admin.usecase.loggedinuser.save.ports; - -import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; - -public interface LoggedInUserSavePortIn { - - void connect(LoggedInUserSaveCmd loggedInUserSaveCmd); -} diff --git a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java b/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java deleted file mode 100644 index 8da77957..00000000 --- a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java +++ /dev/null @@ -1,8 +0,0 @@ -package app.module.admin.usecase.loggedinuser.save.ports; - -import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; - -public interface LoggedInUserSavePortOut { - - void connect(LoggedInUserSaveCmd loggedInUser); -} diff --git a/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml b/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml index fa705ec4..974a53f3 100644 --- a/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml +++ b/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml @@ -42,4 +42,5 @@ WHERE id = #{id} + \ No newline at end of file diff --git a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveDao.java b/core/src/main/java/app/module/core/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveDao.java similarity index 73% rename from admin/src/main/java/app/module/admin/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveDao.java rename to core/src/main/java/app/module/core/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveDao.java index 116fa136..9239302a 100644 --- a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveDao.java +++ b/core/src/main/java/app/module/core/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveDao.java @@ -1,7 +1,7 @@ -package app.module.admin.usecase.loggedinuser.save.adapter.persistence; +package app.module.core.usecase.loggedinuser.save.adapter.persistence; -import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortOut; -import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; +import app.module.core.usecase.loggedinuser.save.ports.LoggedInUserSavePortOut; +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; import app.module.core.config.adapters.persistence.entity.LoggedInUser; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; diff --git a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveMapper.java b/core/src/main/java/app/module/core/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveMapper.java similarity index 78% rename from admin/src/main/java/app/module/admin/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveMapper.java rename to core/src/main/java/app/module/core/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveMapper.java index fc3cc9e8..2a8732a4 100644 --- a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveMapper.java +++ b/core/src/main/java/app/module/core/usecase/loggedinuser/save/adapter/persistence/LoggedInUserSaveMapper.java @@ -1,4 +1,4 @@ -package app.module.admin.usecase.loggedinuser.save.adapter.persistence; +package app.module.core.usecase.loggedinuser.save.adapter.persistence; import app.module.core.config.adapters.persistence.entity.LoggedInUser; import org.apache.ibatis.annotations.Mapper; diff --git a/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java new file mode 100644 index 00000000..8cc8192a --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortIn.java @@ -0,0 +1,8 @@ +package app.module.core.usecase.loggedinuser.save.ports; + +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; + +public interface LoggedInUserSavePortIn { + + void connect(LoggedInUserSaveCmd loggedInUserSaveCmd); +} diff --git a/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java new file mode 100644 index 00000000..0fbd2387 --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/LoggedInUserSavePortOut.java @@ -0,0 +1,8 @@ +package app.module.core.usecase.loggedinuser.save.ports; + +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; + +public interface LoggedInUserSavePortOut { + + void connect(LoggedInUserSaveCmd loggedInUser); +} diff --git a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/LoggedInUserSaveService.java b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/LoggedInUserSaveService.java similarity index 53% rename from admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/LoggedInUserSaveService.java rename to core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/LoggedInUserSaveService.java index 0dc5b3ec..fbae28c6 100644 --- a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/LoggedInUserSaveService.java +++ b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/LoggedInUserSaveService.java @@ -1,8 +1,8 @@ -package app.module.admin.usecase.loggedinuser.save.ports.application; +package app.module.core.usecase.loggedinuser.save.ports.application; -import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortIn; -import app.module.admin.usecase.loggedinuser.save.ports.LoggedInUserSavePortOut; -import app.module.admin.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; +import app.module.core.usecase.loggedinuser.save.ports.LoggedInUserSavePortIn; +import app.module.core.usecase.loggedinuser.save.ports.LoggedInUserSavePortOut; +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/domain/LoggedInUserIdSaveCmd.java b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/domain/LoggedInUserIdSaveCmd.java similarity index 50% rename from admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/domain/LoggedInUserIdSaveCmd.java rename to core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/domain/LoggedInUserIdSaveCmd.java index 37b2318b..f8427c5b 100644 --- a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/domain/LoggedInUserIdSaveCmd.java +++ b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/domain/LoggedInUserIdSaveCmd.java @@ -1,11 +1,7 @@ -package app.module.admin.usecase.loggedinuser.save.ports.application.domain; +package app.module.core.usecase.loggedinuser.save.ports.application.domain; import app.module.core.config.application.enums.AppType; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; @Getter @Setter diff --git a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/domain/LoggedInUserSaveCmd.java b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/domain/LoggedInUserSaveCmd.java similarity index 54% rename from admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/domain/LoggedInUserSaveCmd.java rename to core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/domain/LoggedInUserSaveCmd.java index b18198bd..56e473fd 100644 --- a/admin/src/main/java/app/module/admin/usecase/loggedinuser/save/ports/application/domain/LoggedInUserSaveCmd.java +++ b/core/src/main/java/app/module/core/usecase/loggedinuser/save/ports/application/domain/LoggedInUserSaveCmd.java @@ -1,11 +1,8 @@ -package app.module.admin.usecase.loggedinuser.save.ports.application.domain; +package app.module.core.usecase.loggedinuser.save.ports.application.domain; + +import lombok.*; import java.time.LocalDateTime; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; @Builder @Getter diff --git a/core/src/main/java/app/module/core/usecase/uicode/view/adapters/persistence/UICodeViewDao.java b/core/src/main/java/app/module/core/usecase/uicode/view/adapters/persistence/UICodeViewDao.java index 526af2eb..41523801 100644 --- a/core/src/main/java/app/module/core/usecase/uicode/view/adapters/persistence/UICodeViewDao.java +++ b/core/src/main/java/app/module/core/usecase/uicode/view/adapters/persistence/UICodeViewDao.java @@ -1,6 +1,5 @@ package app.module.core.usecase.uicode.view.adapters.persistence; -import app.module.core.config.adapters.persistence.repository.UICodeRepo; import app.module.core.usecase.uicode.view.ports.UICodeViewPortOut; import app.module.core.usecase.uicode.view.ports.application.domain.UICodeView; import lombok.RequiredArgsConstructor; diff --git a/admin/src/main/resources/mappers/loggedinuser/LoggedInUserSaveMapper.xml b/core/src/main/resources/mappers/loggedinuser/LoggedInUserSaveMapper.xml similarity index 89% rename from admin/src/main/resources/mappers/loggedinuser/LoggedInUserSaveMapper.xml rename to core/src/main/resources/mappers/loggedinuser/LoggedInUserSaveMapper.xml index a21fd09b..655bafe3 100644 --- a/admin/src/main/resources/mappers/loggedinuser/LoggedInUserSaveMapper.xml +++ b/core/src/main/resources/mappers/loggedinuser/LoggedInUserSaveMapper.xml @@ -2,7 +2,7 @@ + namespace="app.module.core.usecase.loggedinuser.save.adapter.persistence.LoggedInUserSaveMapper"> INSERT INTO logged_in_user From 34f97cee240b09febcb548ba299b5a5ce9f4d6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=88=98=ED=98=84?= Date: Thu, 26 Jun 2025 12:03:08 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=ED=94=84=EB=A1=A0=ED=8A=B8=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=9D=B4=EB=A0=A5=20=EC=8C=93=EA=B8=B0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/FrontAuthSuccessEvent.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 front/src/main/java/app/module/front/config/application/security/FrontAuthSuccessEvent.java diff --git a/front/src/main/java/app/module/front/config/application/security/FrontAuthSuccessEvent.java b/front/src/main/java/app/module/front/config/application/security/FrontAuthSuccessEvent.java new file mode 100644 index 00000000..721c451c --- /dev/null +++ b/front/src/main/java/app/module/front/config/application/security/FrontAuthSuccessEvent.java @@ -0,0 +1,56 @@ +package app.module.front.config.application.security; + +import app.module.core.config.application.enums.AppType; +import app.module.core.config.application.util.CommonUtil; +import app.module.core.usecase.loggedinuser.save.ports.LoggedInUserSavePortIn; +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserIdSaveCmd; +import app.module.core.usecase.loggedinuser.save.ports.application.domain.LoggedInUserSaveCmd; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent; +import org.springframework.security.authentication.event.AuthenticationSuccessEvent; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import java.time.LocalDateTime; + +@Component +@RequiredArgsConstructor +@Slf4j +public class FrontAuthSuccessEvent { + + private final LoggedInUserSavePortIn loggedInUserSavePortIn; + + + @EventListener + public void handleAuthenticationSuccessEvent(AuthenticationSuccessEvent event) { + Authentication authentication = event.getAuthentication(); + FrontHouseholdUser householdUser = (FrontHouseholdUser) authentication.getPrincipal(); + + HttpServletRequest request = + ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + // 로그인 이력 쌓기 + loggedInUserSavePortIn.connect( + LoggedInUserSaveCmd.builder() + .loggedInUserId( + LoggedInUserIdSaveCmd.builder() + .appType(AppType.FRONT) + .id(authentication.getName()) + .build()) + .clientIP(CommonUtil.getClientIP(request)) + .lastLoggedInAt(LocalDateTime.now()) + .build()); + + } + + @EventListener + public void handleAuthenticationFailureEvent(AbstractAuthenticationFailureEvent event) { + Exception e = event.getException(); + Authentication authentication = event.getAuthentication(); + log.warn("Unsuccessful authentication result: {}", authentication, e); + } +} From 6b54f605c8ed5d5605ee5a763e5ec7928d539cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=88=98=ED=98=84?= Date: Thu, 26 Jun 2025 13:33:57 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=EA=B3=B5=EC=8B=9D=EA=B0=80=EC=9E=85?= =?UTF-8?q?=EC=84=BC=ED=84=B0=20=EB=B0=94=EB=A1=9C=EA=B0=80=EA=B8=B0=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/main/resources/templates/security/login.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/admin/src/main/resources/templates/security/login.html b/admin/src/main/resources/templates/security/login.html index 6cde9987..0c6104a7 100644 --- a/admin/src/main/resources/templates/security/login.html +++ b/admin/src/main/resources/templates/security/login.html @@ -40,9 +40,6 @@ 로그인 -
    From e90505d1901f8d4c13706ba45d1aa212b751e7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=9A=B0=EC=84=B1?= Date: Thu, 26 Jun 2025 15:22:37 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Excel=EB=8B=A4=EC=9A=B4=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/util/ExcelWriterUtil.java | 134 ++++++++++++++++++ .../application/util/model/ExcelSheetDto.java | 45 ++++++ .../web/GetExcelMultiSheetController.java | 124 ++++++++++++++++ 3 files changed, 303 insertions(+) create mode 100644 admin/src/main/java/app/module/admin/config/application/util/ExcelWriterUtil.java create mode 100644 admin/src/main/java/app/module/admin/config/application/util/model/ExcelSheetDto.java create mode 100644 admin/src/main/java/app/module/admin/usecase/excel/getExcelMultilSheet/adapters/web/GetExcelMultiSheetController.java diff --git a/admin/src/main/java/app/module/admin/config/application/util/ExcelWriterUtil.java b/admin/src/main/java/app/module/admin/config/application/util/ExcelWriterUtil.java new file mode 100644 index 00000000..032070d4 --- /dev/null +++ b/admin/src/main/java/app/module/admin/config/application/util/ExcelWriterUtil.java @@ -0,0 +1,134 @@ +package app.module.admin.config.application.util; + +import app.module.admin.config.application.util.model.ExcelSheetDto; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.stereotype.Component; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.List; + + +@Component +public class ExcelWriterUtil { + public static byte[] writeExcel(List sheets) { + try (Workbook workbook = new XSSFWorkbook()) { + CellStyle bodyStyle = createBodyStyle(workbook); + CellStyle commaStyle = createCommaStyle(workbook); + + for (ExcelSheetDto sheetDto : sheets) { + Sheet sheet = workbook.createSheet(sheetDto.getSheetName()); + List headers = sheetDto.getHeaders(); + List> dataRows = sheetDto.getData(); + + // 헤더 작성 + Row headerRow = sheet.createRow(0); + for (int col = 0; col < headers.size(); col++) { + String headerText = headers.get(col); + + IndexedColors bgColor = sheetDto.getHeaderBgColors() != null + ? sheetDto.getHeaderBgColors().getOrDefault(col, IndexedColors.GREY_25_PERCENT) + : IndexedColors.GREY_25_PERCENT; + + CellStyle headerStyle = createHeaderStyle(workbook, bgColor); + + Cell cell = headerRow.createCell(col); + cell.setCellValue(headerText); + cell.setCellStyle(headerStyle); + } + + // 데이터 작성 + for (int r = 0; r < dataRows.size(); r++) { + Row row = sheet.createRow(r + 1); + List rowData = dataRows.get(r); + for (int c = 0; c < rowData.size(); c++) { + Cell cell = row.createCell(c); + String value = rowData.get(c); + if (sheetDto.getCommaColumns() != null && + sheetDto.getCommaColumns().contains(c) && + isNumeric(value)) { + cell.setCellValue(Double.parseDouble(value)); + cell.setCellStyle(commaStyle); + } else { + cell.setCellValue(value); + cell.setCellStyle(bodyStyle); + } + } + } + + // 컬럼 너비 수동 계산 + for (int col = 0; col < headers.size(); col++) { + int maxLength = getByteLength(headers.get(col)); + for (List rowData : dataRows) { + if (col < rowData.size()) { + int length = getByteLength(rowData.get(col)); + if (length > maxLength) { + maxLength = length; + } + } + } + sheet.setColumnWidth(col, (maxLength + 2) * 256); + } + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + workbook.write(out); + return out.toByteArray(); + + } catch (IOException e) { + throw new RuntimeException("엑셀 생성 실패", e); + } + } + + private static boolean isNumeric(String value) { + if (value == null) return false; + try { + Double.parseDouble(value); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + private static int getByteLength(String value) { + return value == null ? 0 : value.getBytes().length; + } + + private static CellStyle createHeaderStyle(Workbook workbook, IndexedColors bgColor) { + CellStyle style = workbook.createCellStyle(); + Font font = workbook.createFont(); + font.setBold(true); + style.setFont(font); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setFillForegroundColor(bgColor.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + setBorder(style); + return style; + } + + private static CellStyle createBodyStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + style.setAlignment(HorizontalAlignment.LEFT); + style.setVerticalAlignment(VerticalAlignment.CENTER); + setBorder(style); + return style; + } + + private static CellStyle createCommaStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + style.setAlignment(HorizontalAlignment.RIGHT); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setDataFormat(workbook.createDataFormat().getFormat("#,##0")); + setBorder(style); + return style; + } + + private static void setBorder(CellStyle style) { + style.setBorderTop(BorderStyle.THIN); + style.setBorderBottom(BorderStyle.THIN); + style.setBorderLeft(BorderStyle.THIN); + style.setBorderRight(BorderStyle.THIN); + } +} diff --git a/admin/src/main/java/app/module/admin/config/application/util/model/ExcelSheetDto.java b/admin/src/main/java/app/module/admin/config/application/util/model/ExcelSheetDto.java new file mode 100644 index 00000000..176d6ba7 --- /dev/null +++ b/admin/src/main/java/app/module/admin/config/application/util/model/ExcelSheetDto.java @@ -0,0 +1,45 @@ +package app.module.admin.config.application.util.model; + +import org.apache.poi.ss.usermodel.IndexedColors; +import java.util.List; +import java.util.Set; + +import java.util.Map; + +public class ExcelSheetDto { + /** + * 시트명 + */ + private String sheetName; + /** + * 테이블 해더 리스트 + */ + private List headers; + /** + * 데이터 리스트 (해더와 같아야 한다. 값이 없다면 null이라도 넣어줘야해요.) + */ + private List> data; + /** + * 입력한 데이터 중 comma가 필요한 라인 선택 0 부터 + */ + private Set commaColumns; + /** + * 해더의 배경색 지정 : 0부터 시작 + */ + private Map headerBgColors; // 💡 추가: 컬럼별 배경색 + + public ExcelSheetDto(String sheetName, List headers, List> data, + Set commaColumns, Map headerBgColors) { + this.sheetName = sheetName; + this.headers = headers; + this.data = data; + this.commaColumns = commaColumns; + this.headerBgColors = headerBgColors; + } + + public String getSheetName() { return sheetName; } + public List getHeaders() { return headers; } + public List> getData() { return data; } + public Set getCommaColumns() { return commaColumns; } + public Map getHeaderBgColors() { return headerBgColors; } +} diff --git a/admin/src/main/java/app/module/admin/usecase/excel/getExcelMultilSheet/adapters/web/GetExcelMultiSheetController.java b/admin/src/main/java/app/module/admin/usecase/excel/getExcelMultilSheet/adapters/web/GetExcelMultiSheetController.java new file mode 100644 index 00000000..9f909e84 --- /dev/null +++ b/admin/src/main/java/app/module/admin/usecase/excel/getExcelMultilSheet/adapters/web/GetExcelMultiSheetController.java @@ -0,0 +1,124 @@ +package app.module.admin.usecase.excel.getExcelMultilSheet.adapters.web; + +import app.module.admin.config.application.util.model.ExcelSheetDto; +import lombok.RequiredArgsConstructor; +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.RestController; + +import app.module.admin.config.application.util.ExcelWriterUtil; +import java.util.List; +import java.util.Set; +import org.apache.poi.ss.usermodel.IndexedColors; +import java.util.Map; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +@RestController +@RequiredArgsConstructor +class GetExcelMultiSheetController { + + @GetMapping("/api/admin/excel/multisheet") + public ResponseEntity exportHouseholdExcel() { + + // 시트 1: 조사 대상 목록 (타이틀 10개) + ExcelSheetDto sheet1 = new ExcelSheetDto( + "조사 대상", + List.of("ID", "이름", "성별", "나이", "주소", "전화번호", "이메일", "등록일", "상태", "비고"), + List.of( + List.of("1", "홍길동", "남", "30", "서울", "010-1234-5678", "hong@example.com", "2024-01-01", "완료", ""), + List.of("2", "김영희", "여", "28", "부산", "010-2222-3333", "kim@example.com", "2024-01-02", "미완료", "응답 거부") + ), + Set.of(3), // 나이 컬럼에 콤마 포맷 적용 (예시용) + Map.of( + 0, IndexedColors.LIGHT_CORNFLOWER_BLUE, + 3, IndexedColors.LIGHT_YELLOW, + 7, IndexedColors.LIGHT_ORANGE + ) + ); + + /* + + 취득 데이터는 변환해서 넣어줘도 됩니다. + List rawList = ... // List를 캐스팅 or 변환 + List> excelData = rawList.stream() + .map(dto -> List.of( + String.valueOf(dto.getId()), + dto.getName(), + dto.getGender(), + String.valueOf(dto.getAge()), + dto.getAddress(), + dto.getPhone(), + dto.getEmail(), + dto.getRegDate().toString(), + dto.getStatus(), + dto.getNote() + )) + .toList(); + + + ExcelSheetDto sheet = new ExcelSheetDto( + "조사 대상", + List.of("ID", "이름", "성별", "나이", "주소", "전화번호", "이메일", "등록일", "상태", "비고"), + excelData, // <----------------------------------@@@@@@@@@@@@@@@@ + Set.of(3), + Map.of( + 0, IndexedColors.LIGHT_CORNFLOWER_BLUE, + 3, IndexedColors.LIGHT_YELLOW, + 7, IndexedColors.LIGHT_ORANGE + ) + ); + */ + + // 시트 2: 응답 통계 (타이틀 7개) + ExcelSheetDto sheet2 = new ExcelSheetDto( + "응답 통계", + List.of("구분", "총건수", "응답수", "미응답", "응답률", "평균시간", "비고"), + List.of( + List.of("전체", "1000", "850", "150", "85%", "5분", ""), + List.of("서울", "400", "360", "40", "90%", "4분", "") + ), + Set.of(1, 2, 3), // 숫자열에 콤마 포맷 적용 + Map.of( + 1, IndexedColors.LIGHT_GREEN, + 2, IndexedColors.LIGHT_GREEN, + 3, IndexedColors.LIGHT_YELLOW + ) + ); + + // 시트 3: 조사자별 실적 (타이틀 5개) + ExcelSheetDto sheet3 = new ExcelSheetDto( + "조사자 실적", + List.of("조사자명", "조사건수", "완료건수", "진행률", "비고"), + List.of( + List.of("박조사", "200", "180", "90%", ""), + List.of("이조사", "150", "100", "66.6%", "") + ), + Set.of(1, 2), // 조사건수, 완료건수에 콤마 포맷 + Map.of( + 0, IndexedColors.LIGHT_TURQUOISE, + 1, IndexedColors.LIGHT_ORANGE, + 2, IndexedColors.LIGHT_ORANGE + ) + ); + + // 시트 모음 + List sheets = List.of(sheet1, sheet2, sheet3); + + byte[] excel = ExcelWriterUtil.writeExcel(sheets); + + + String rawFileName = "조사결과_" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".xlsx"; + String encodedFileName = URLEncoder.encode(rawFileName, StandardCharsets.UTF_8).replaceAll("\\+", "%20"); + + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFileName) + .body(excel); + } +} \ No newline at end of file From 8241b3d77d57d504544e2fc1799a8386755b69bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=88=98=ED=98=84?= Date: Thu, 26 Jun 2025 15:55:09 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20vm=EC=98=B5=EC=85=98=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20-Dpath.upload.storage=3DLOCAL=20=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=ED=95=B4=EC=A3=BC=EC=84=B8=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- .../adapters/persistence/CreateNoticeDao.java | 2 +- .../persistence/CreateNoticeMapper.java | 2 +- .../adapters/persistence/GetNoticeDao.java | 8 ++- .../persistence/RemoveNoticesDao.java | 2 +- .../persistence/RemoveNoticesMapper.java | 2 +- .../adapters/persistence/UpdateNoticeDao.java | 23 ++----- .../persistence/UpdateNoticeMapper.java | 5 -- .../model/CreateUploadFileParam.java | 18 ----- .../adapters/web/UpdateNoticeController.java | 15 ++++- .../web/EditorImageUploadController.java | 6 +- .../mappers/notice/CreateNoticeMapper.xml | 23 +++---- .../mappers/notice/GetNoticeMapper.xml | 9 +-- .../mappers/notice/GetNoticesMapper.xml | 7 +- .../mappers/notice/RemoveNoticesMapper.xml | 8 +-- .../mappers/notice/UpdateNoticeMapper.xml | 26 -------- .../application/enums/FileStorageType.java | 5 ++ .../application/enums/FileUploadType.java | 19 +++--- .../application/util/SftpFileDeleteUtil.java | 4 +- .../adapters/persistence/GetArticleDao.java | 9 ++- .../adapters/persistence/CreateFileDao.java | 12 +++- .../application/SaveToStorageService.java | 7 +- .../adapters/persistence/UpdateFileDao.java | 66 +++++++++++++++++++ .../persistence/UpdateFileMapper.java | 14 ++++ .../updateFile/ports/UpdateFilePortIn.java | 8 +++ .../updateFile/ports/UpdateFilePortOut.java | 8 +++ .../ports/application/UpdateFileService.java | 20 ++++++ .../application/domain/UpdateFileCmd.java | 19 ++++++ .../domain/UpdateUploadFileParam.java | 18 +++++ .../application/domain/UploadFileDto.java | 43 ++++++++++++ .../adapters/web/GetAttachmentController.java | 5 +- .../ports/application/URISaveService.java | 6 +- .../ports/application/FindUserService.java | 9 ++- .../mappers/file/UpdateFileMapper.xml | 47 +++++++++++++ .../resources/sql/schema/02_create-all.sql | 35 +--------- 35 files changed, 355 insertions(+), 160 deletions(-) delete mode 100644 admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/model/CreateUploadFileParam.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileDao.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileMapper.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortIn.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortOut.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/UpdateFileService.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateFileCmd.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateUploadFileParam.java create mode 100644 core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UploadFileDto.java create mode 100644 core/src/main/resources/mappers/file/UpdateFileMapper.xml diff --git a/README.md b/README.md index f24fe164..38513630 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ recycle 의 demo 가 궁금하다면 아래 URL 에서 확인 해주세요. -Dspring.datasource.username=ko_research -Dspring.datasource.password=koresearch1@#4 -Daes.secret-key=092HW829O0A0AVR0 --Dpath.upload.storage=SFTP +-Dpath.upload.storage=LOCAL -Dpath.upload.sftp.public=/home/etribe/data/upload -Dpath.upload.sftp.tmpdir=${user.home}/upload/tmpdir -Dfile.upload.sftp.ip=115.68.193.117 @@ -121,6 +121,9 @@ recycle 의 demo 가 궁금하다면 아래 URL 에서 확인 해주세요. -Dfile.upload.sftp.password=Etribe@3415 -Dfile.upload.sftp.port=22 ``` +** 주의 : 운영서버일 경우 -Dpath.upload.storage=SFTP로 설정 + + ## JDBC 및 데이터 핸들링 구성 옵션 diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeDao.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeDao.java index 3b62b575..ba7dceeb 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeDao.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeDao.java @@ -40,7 +40,7 @@ class CreateNoticeDao implements CreateNoticePortOut { mapper.createNotice(dto); if (dto.getFileMappingId() != null && !dto.getFileMappingId().isEmpty()) { - mapper.createNoticeHasUploadFile(new CreateNoticeHasUploadFilesParam( + mapper.createNoticeUploadFile(new CreateNoticeHasUploadFilesParam( dto.getId(), dto.getFileMappingId().stream() .map(Long::parseLong) diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeMapper.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeMapper.java index 5784775f..20c663fa 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeMapper.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/createNotice/adapters/persistence/CreateNoticeMapper.java @@ -7,5 +7,5 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface CreateNoticeMapper { void createNotice(CreateNoticeDto dto); - void createNoticeHasUploadFile(CreateNoticeHasUploadFilesParam param); + void createNoticeUploadFile(CreateNoticeHasUploadFilesParam param); } diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/getNotice/adapters/persistence/GetNoticeDao.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/getNotice/adapters/persistence/GetNoticeDao.java index ddde16d9..485be483 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/getNotice/adapters/persistence/GetNoticeDao.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/getNotice/adapters/persistence/GetNoticeDao.java @@ -4,8 +4,10 @@ import app.module.admin.usecase.communication.notice.getNotice.ports.GetNoticePo import app.module.admin.usecase.communication.notice.getNotice.ports.application.domain.GetNotice; import app.module.admin.usecase.communication.notice.getNotice.ports.application.domain.GetNoticeCmd; import app.module.admin.usecase.communication.notice.getNotice.ports.application.domain.GetNoticeUploadFile; +import app.module.core.config.application.enums.FileStorageType; import app.module.core.usecase.file.url.application.port.in.FileUrlPortIn; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -19,6 +21,8 @@ class GetNoticeDao implements GetNoticePortOut { private final GetNoticeMapper mapper; private final FileUrlPortIn fileUrlPortIn; + @Value("${path.upload.storage}") + private String uploadStorageType; @Override @Transactional @@ -35,13 +39,13 @@ class GetNoticeDao implements GetNoticePortOut { // 참조 URL 전달 uploadFile.setReferURL( fileUrlPortIn.getInline( - uploadFile.getType().getFileStorageType(), + FileStorageType.valueOf(uploadStorageType), uploadFile.getPath(), uploadFile.getName())); // attachment URL 전달 uploadFile.setAttachmentURL( fileUrlPortIn.getAttachment( - uploadFile.getType().getFileStorageType(), uploadFile.getId())); + FileStorageType.valueOf(uploadStorageType), uploadFile.getId())); return uploadFile; }) diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesDao.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesDao.java index 15af73d6..d87002b5 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesDao.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesDao.java @@ -20,7 +20,7 @@ class RemoveNoticesDao implements RemoveNoticesPortOut { String loginUser = CommonUtil.getLoginUsername();; LocalDateTime now = LocalDateTime.now(); - mapper.deleteNoticeHasFiles( + mapper.deleteNoticeUploadFiles( new RemoveNoticesParam(command.getRemoveIds(), now, loginUser, now, loginUser)); mapper.deleteNotices( new RemoveNoticesParam(command.getRemoveIds(), now, loginUser, now, loginUser)); diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesMapper.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesMapper.java index 6f2fdcce..d5fbdac1 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesMapper.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/removeNotices/adapters/persistence/RemoveNoticesMapper.java @@ -6,5 +6,5 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface RemoveNoticesMapper { void deleteNotices(RemoveNoticesParam param); - void deleteNoticeHasFiles(RemoveNoticesParam param); + void deleteNoticeUploadFiles(RemoveNoticesParam param); } diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java index e4ed8ee0..77a0e82b 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeDao.java @@ -1,24 +1,25 @@ package app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence; -import app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence.model.CreateUploadFileParam; import app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence.model.UpdateNoticeDto; import app.module.admin.usecase.communication.notice.updateNotice.ports.UpdateNoticePortOut; import app.module.admin.usecase.communication.notice.updateNotice.ports.application.domain.UpdateNoticeCmd; -import app.module.core.config.adapters.persistence.entity.NoticeHasUploadFile; +import app.module.core.config.application.annotation.UpdateCommand; import app.module.core.config.application.util.CommonUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Repository; import java.time.LocalDateTime; +@Slf4j @Repository @RequiredArgsConstructor class UpdateNoticeDao implements UpdateNoticePortOut { private final UpdateNoticeMapper mapper; - @Override + @UpdateCommand public void operate(UpdateNoticeCmd command) { mapper.updateNotice( new UpdateNoticeDto( @@ -33,21 +34,5 @@ class UpdateNoticeDao implements UpdateNoticePortOut { CommonUtil.getLoginUsername() )); - // 첨부파일 초기화 - mapper.deleteFileUploads(new NoticeHasUploadFile(command.getId())); - - // 첨부파일 있을 시, 등록 - if (command.getFileMappingId() != null && !command.getFileMappingId().isEmpty()) { - mapper.createFileUploads(new CreateUploadFileParam( - command.getId(), - command.getFileMappingId().stream() - .map(Long::parseLong) - .toList(), - LocalDateTime.now(), - CommonUtil.getLoginUsername(), - LocalDateTime.now(), - CommonUtil.getLoginUsername() - )); - } } } diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeMapper.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeMapper.java index f2b2c4ef..742522ff 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeMapper.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/UpdateNoticeMapper.java @@ -1,14 +1,9 @@ package app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence; -import app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence.model.CreateUploadFileParam; import app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence.model.UpdateNoticeDto; -import app.module.core.config.adapters.persistence.entity.ArticleHasUploadFile; -import app.module.core.config.adapters.persistence.entity.NoticeHasUploadFile; import org.apache.ibatis.annotations.Mapper; @Mapper public interface UpdateNoticeMapper { void updateNotice(UpdateNoticeDto dto); - void deleteFileUploads(NoticeHasUploadFile noticeHasUploadFile); - void createFileUploads(CreateUploadFileParam param); } diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/model/CreateUploadFileParam.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/model/CreateUploadFileParam.java deleted file mode 100644 index 99fce30b..00000000 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/persistence/model/CreateUploadFileParam.java +++ /dev/null @@ -1,18 +0,0 @@ -package app.module.admin.usecase.communication.notice.updateNotice.adapters.persistence.model; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.time.LocalDateTime; -import java.util.List; - -@Getter -@AllArgsConstructor -public class CreateUploadFileParam { - private Long id; - private List fileMappingId; - private LocalDateTime createdAt; - private String createdBy; - private LocalDateTime updatedAt; - private String updatedBy; -} diff --git a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/web/UpdateNoticeController.java b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/web/UpdateNoticeController.java index 7159cd89..079c05e7 100644 --- a/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/web/UpdateNoticeController.java +++ b/admin/src/main/java/app/module/admin/usecase/communication/notice/updateNotice/adapters/web/UpdateNoticeController.java @@ -3,6 +3,9 @@ package app.module.admin.usecase.communication.notice.updateNotice.adapters.web; import app.module.admin.usecase.communication.notice.updateNotice.adapters.web.model.UpdateNoticeReqVO; import app.module.admin.usecase.communication.notice.updateNotice.ports.UpdateNoticePortIn; import app.module.admin.usecase.communication.notice.updateNotice.ports.application.domain.UpdateNoticeCmd; +import app.module.core.config.application.enums.FileUploadType; +import app.module.core.usecase.file.updateFile.ports.UpdateFilePortIn; +import app.module.core.usecase.file.updateFile.ports.application.domain.UpdateFileCmd; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -16,6 +19,7 @@ import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor class UpdateNoticeController { private final UpdateNoticePortIn updateNoticePortIn; + private final UpdateFilePortIn updateFilePortIn; @PutMapping(path = "/api/communication/notices/update") ResponseEntity operate(@RequestBody @Valid UpdateNoticeReqVO reqVO, BindingResult bindingResult) { @@ -26,6 +30,13 @@ class UpdateNoticeController { .body(bindingResult.getFieldErrors()); } + updateFilePortIn.operate( + new UpdateFileCmd( + reqVO.getId(), + reqVO.getFileMappingId().stream().map(Long::parseLong).toList(), + FileUploadType.NOTICE) + ); + updateNoticePortIn.operate( new UpdateNoticeCmd( reqVO.getId(), @@ -34,8 +45,8 @@ class UpdateNoticeController { reqVO.getVisible(), reqVO.getStartDate(), reqVO.getEndDate(), - reqVO.getFileMappingId() - )); + reqVO.getFileMappingId()) + ); return ResponseEntity.status(HttpStatus.OK).body(reqVO); } diff --git a/admin/src/main/java/app/module/admin/usecase/editor/adapters/web/EditorImageUploadController.java b/admin/src/main/java/app/module/admin/usecase/editor/adapters/web/EditorImageUploadController.java index 0f255841..2b07450e 100644 --- a/admin/src/main/java/app/module/admin/usecase/editor/adapters/web/EditorImageUploadController.java +++ b/admin/src/main/java/app/module/admin/usecase/editor/adapters/web/EditorImageUploadController.java @@ -1,11 +1,13 @@ package app.module.admin.usecase.editor.adapters.web; +import app.module.core.config.application.enums.FileStorageType; import app.module.core.config.application.enums.FileUploadType; import app.module.core.usecase.file.saveToStorage.ports.SaveToStoragePortIn; import app.module.core.usecase.file.saveToStorage.ports.application.domain.SaveToStorage; import app.module.core.usecase.file.url.application.port.in.FileUrlPortIn; import java.io.IOException; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -18,6 +20,8 @@ public class EditorImageUploadController { private final SaveToStoragePortIn saveToStoragePortIn; private final FileUrlPortIn fileUrlPortIn; + @Value("${path.upload.storage}") + private String uploadStorageType; @PostMapping(path = "/api/editorImage/upload") ResponseEntity editorImageUpload(MultipartFile editorImage) throws IOException { @@ -27,7 +31,7 @@ public class EditorImageUploadController { return ResponseEntity.status(HttpStatus.OK) .body( fileUrlPortIn.getInline( - saveToStorage.getType().getFileStorageType(), + FileStorageType.valueOf(uploadStorageType), saveToStorage.getPath(), saveToStorage.getName())); } diff --git a/admin/src/main/resources/mappers/notice/CreateNoticeMapper.xml b/admin/src/main/resources/mappers/notice/CreateNoticeMapper.xml index e5d1c88a..7d39042c 100644 --- a/admin/src/main/resources/mappers/notice/CreateNoticeMapper.xml +++ b/admin/src/main/resources/mappers/notice/CreateNoticeMapper.xml @@ -37,23 +37,16 @@ ) - - - INSERT INTO notice_has_upload_file - ( - notice_id, - upload_files_id, - - ) - VALUES + + update upload_file + set mapping_id = #{id}, + + where id IN ( - ( - #{id}, - #{fileId}, - - ) + #{fileId} - + ) + \ No newline at end of file diff --git a/admin/src/main/resources/mappers/notice/GetNoticeMapper.xml b/admin/src/main/resources/mappers/notice/GetNoticeMapper.xml index 1a0fb58c..bbab4a30 100644 --- a/admin/src/main/resources/mappers/notice/GetNoticeMapper.xml +++ b/admin/src/main/resources/mappers/notice/GetNoticeMapper.xml @@ -29,8 +29,7 @@ resultType="app.module.admin.usecase.communication.notice.getNotice.ports.application.domain.GetNoticeUploadFile"> /* getUploadFiles 상세 게시글 조회 시, 첨부파일 조회 */ SELECT - awuf.notice_id AS noticeId, - awuf.upload_files_id AS uploadfileId, + uf.mapping_id, uf.id AS id, uf.created_at AS createdAt, uf.created_by AS createdBy, @@ -41,9 +40,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} AND awuf.is_deleted = false + FROM upload_file uf + WHERE uf.mapping_id = #{id} AND uf.is_deleted = false AND uf.type ='NOTICE' \ No newline at end of file diff --git a/admin/src/main/resources/mappers/notice/GetNoticesMapper.xml b/admin/src/main/resources/mappers/notice/GetNoticesMapper.xml index c0ccc944..237d3fed 100644 --- a/admin/src/main/resources/mappers/notice/GetNoticesMapper.xml +++ b/admin/src/main/resources/mappers/notice/GetNoticesMapper.xml @@ -78,16 +78,15 @@ resultType="app.module.admin.usecase.communication.notice.getNoticesUI.ports.application.domain.GetNoticeFiles"> /* getUploadFiles : 게시물 리스트의 대표 이미지 */ SELECT - awuf.notice_id, + uf.mapping_id as notice_id, uf.id, uf.type, uf.path, uf.name, uf.origin_name, uf.file_length - FROM notice_has_upload_file awuf - INNER JOIN upload_file uf ON awuf.upload_files_id = uf.id - WHERE awuf.notice_id IN + FROM upload_file uf + WHERE uf.mapping_id IN #{id} diff --git a/admin/src/main/resources/mappers/notice/RemoveNoticesMapper.xml b/admin/src/main/resources/mappers/notice/RemoveNoticesMapper.xml index d253a98a..e138634a 100644 --- a/admin/src/main/resources/mappers/notice/RemoveNoticesMapper.xml +++ b/admin/src/main/resources/mappers/notice/RemoveNoticesMapper.xml @@ -13,11 +13,11 @@ - - /* deleteNoticeHasFiles : 게시물-파일 매핑 논리 삭제 */ - UPDATE notice_has_upload_file + + /* deleteNoticeUploadFiles : 게시물-파일 매핑 논리 삭제 */ + UPDATE upload_file SET - WHERE notice_id IN + WHERE type='NOTICE' and mapping_id IN #{id} diff --git a/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml b/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml index 974a53f3..00a9cc9e 100644 --- a/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml +++ b/admin/src/main/resources/mappers/notice/UpdateNoticeMapper.xml @@ -4,32 +4,6 @@ - - /* deleteFileUploads 게시글 수정 시, 첨부파일 join 데이터 삭제 */ - UPDATE notice_has_upload_file - SET - - WHERE notice_id = #{noticeId} - - - - /* createFileUploads 게시글 수정 시, 첨부파일 join 데이터 등록 */ - INSERT INTO notice_has_upload_file - ( - notice_id, - upload_files_id, - - ) - VALUES - - ( - #{id}, - #{fileId}, - - ) - - - /* updateNotice 게시글 수정 */ UPDATE notice diff --git a/core/src/main/java/app/module/core/config/application/enums/FileStorageType.java b/core/src/main/java/app/module/core/config/application/enums/FileStorageType.java index 9b3a3b2f..0a4cee07 100644 --- a/core/src/main/java/app/module/core/config/application/enums/FileStorageType.java +++ b/core/src/main/java/app/module/core/config/application/enums/FileStorageType.java @@ -10,4 +10,9 @@ public enum FileStorageType { S3("AWS S3 스토리지"), SFTP("SFTP"); private final String desc; + private String name; + + public String getName() { + return name(); + } } diff --git a/core/src/main/java/app/module/core/config/application/enums/FileUploadType.java b/core/src/main/java/app/module/core/config/application/enums/FileUploadType.java index fe7e5dff..f16cdffe 100644 --- a/core/src/main/java/app/module/core/config/application/enums/FileUploadType.java +++ b/core/src/main/java/app/module/core/config/application/enums/FileUploadType.java @@ -10,12 +10,12 @@ import lombok.RequiredArgsConstructor; @JsonFormat(shape = JsonFormat.Shape.OBJECT) public enum FileUploadType { // URI og:image 용 이미지 파일 - OG_IMAGE(FileStorageType.LOCAL, "/ogImage", Set.of(AcceptableFileType.IMAGE)), + OG_IMAGE(Set.of(FileStorageType.LOCAL), "/ogImage", Set.of(AcceptableFileType.IMAGE)), // WEB Editor 이미지 파일 - EDITOR_IMAGE(FileStorageType.LOCAL, "/editorImage", Set.of(AcceptableFileType.IMAGE)), + EDITOR_IMAGE(Set.of(FileStorageType.LOCAL), "/editorImage", Set.of(AcceptableFileType.IMAGE)), PUBLIC( - FileStorageType.LOCAL, + Set.of(FileStorageType.LOCAL), "/common", Set.of( AcceptableFileType.IMAGE, @@ -28,7 +28,7 @@ public enum FileUploadType { AcceptableFileType.PDF, AcceptableFileType.ZIP)), PRIVATE( - FileStorageType.LOCAL, + Set.of(FileStorageType.LOCAL), "/private", Set.of( AcceptableFileType.IMAGE, @@ -41,7 +41,10 @@ public enum FileUploadType { AcceptableFileType.PDF, AcceptableFileType.ZIP)), NOTICE( - FileStorageType.SFTP, + Set.of( + FileStorageType.SFTP, + FileStorageType.LOCAL + ), "/notice", Set.of( AcceptableFileType.IMAGE, @@ -55,15 +58,15 @@ public enum FileUploadType { AcceptableFileType.ZIP)), RECEIPT( - FileStorageType.SFTP, - "/receipt", + Set.of(FileStorageType.SFTP,FileStorageType.LOCAL), + "/receipt", Set.of( AcceptableFileType.IMAGE ) ); - private final FileStorageType fileStorageType; + private final Set fileStorageType; private final String subPath; private final Set acceptableFileTypes; diff --git a/core/src/main/java/app/module/core/config/application/util/SftpFileDeleteUtil.java b/core/src/main/java/app/module/core/config/application/util/SftpFileDeleteUtil.java index 202541cb..5e616b7e 100644 --- a/core/src/main/java/app/module/core/config/application/util/SftpFileDeleteUtil.java +++ b/core/src/main/java/app/module/core/config/application/util/SftpFileDeleteUtil.java @@ -1,7 +1,7 @@ package app.module.core.config.application.util; -import app.module.core.config.adapters.persistence.entity.UploadFile; import app.module.core.usecase.file.saveToStorage.ports.application.strategy.SftpConnector; +import app.module.core.usecase.file.updateFile.ports.application.domain.UploadFileDto; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; @@ -28,7 +28,7 @@ public class SftpFileDeleteUtil { * @throws JSchException SFTP 연결 오류 * @throws SftpException SFTP 작업 오류 */ - public void deleteRealFile(UploadFile deleteFile) throws JSchException, SftpException { + public void deleteRealFile(UploadFileDto deleteFile) throws JSchException, SftpException { if (deleteFile == null || deleteFile.getPath() == null || deleteFile.getName() == null) { log.error("Invalid file information: {}", deleteFile); throw new IllegalArgumentException("Invalid file information"); diff --git a/core/src/main/java/app/module/core/usecase/article/getArticle/adapters/persistence/GetArticleDao.java b/core/src/main/java/app/module/core/usecase/article/getArticle/adapters/persistence/GetArticleDao.java index db4a6944..bbdb6844 100644 --- a/core/src/main/java/app/module/core/usecase/article/getArticle/adapters/persistence/GetArticleDao.java +++ b/core/src/main/java/app/module/core/usecase/article/getArticle/adapters/persistence/GetArticleDao.java @@ -1,5 +1,6 @@ package app.module.core.usecase.article.getArticle.adapters.persistence; +import app.module.core.config.application.enums.FileStorageType; import app.module.core.usecase.article.getArticle.ports.GetArticlePortOut; import app.module.core.usecase.article.getArticle.ports.application.domain.GetArticle; import app.module.core.usecase.article.getArticle.ports.application.domain.GetArticleCmd; @@ -9,6 +10,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -19,6 +21,9 @@ class GetArticleDao implements GetArticlePortOut { private final GetArticleMapper mapper; private final FileUrlPortIn fileUrlPortIn; + @Value("${path.upload.storage}") + private String uploadStorageType; + @Override @Transactional public Optional operate(GetArticleCmd command) { @@ -34,13 +39,13 @@ class GetArticleDao implements GetArticlePortOut { // 참조 URL 전달 uploadFile.setReferURL( fileUrlPortIn.getInline( - uploadFile.getType().getFileStorageType(), + FileStorageType.valueOf(uploadStorageType), uploadFile.getPath(), uploadFile.getName())); // attachment URL 전달 uploadFile.setAttachmentURL( fileUrlPortIn.getAttachment( - uploadFile.getType().getFileStorageType(), uploadFile.getId())); + FileStorageType.valueOf(uploadStorageType), uploadFile.getId())); return uploadFile; }) diff --git a/core/src/main/java/app/module/core/usecase/file/createFile/adapters/persistence/CreateFileDao.java b/core/src/main/java/app/module/core/usecase/file/createFile/adapters/persistence/CreateFileDao.java index dec0dc35..d59e4618 100644 --- a/core/src/main/java/app/module/core/usecase/file/createFile/adapters/persistence/CreateFileDao.java +++ b/core/src/main/java/app/module/core/usecase/file/createFile/adapters/persistence/CreateFileDao.java @@ -1,12 +1,14 @@ package app.module.core.usecase.file.createFile.adapters.persistence; import app.module.core.config.adapters.persistence.entity.UploadFile; +import app.module.core.config.application.enums.FileStorageType; import app.module.core.usecase.file.createFile.ports.CreateFilePortOut; import app.module.core.usecase.file.createFile.ports.application.domain.CreateFile; import app.module.core.usecase.file.createFile.ports.application.domain.CreateFileCmd; import app.module.core.usecase.file.url.application.port.in.FileUrlPortIn; import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; @Repository @@ -15,6 +17,10 @@ class CreateFileDao implements CreateFilePortOut { private final CreateFileMapper mapper; private final FileUrlPortIn fileUrlPortIn; + @Value("${path.upload.storage}") + private String uploadStorageType; + + @Override public Optional operate(CreateFileCmd command) { UploadFile uploadFile = new UploadFile( @@ -23,7 +29,7 @@ class CreateFileDao implements CreateFilePortOut { command.getPath(), command.getName(), command.getOriginName(), - command.getFileLength()); + command.getFileLength() ); mapper.insertFile(uploadFile); @@ -37,11 +43,11 @@ class CreateFileDao implements CreateFilePortOut { uploadFile.getFileLength(), // 참조 URL 전달 fileUrlPortIn.getInline( - uploadFile.getType().getFileStorageType(), + FileStorageType.valueOf(uploadStorageType), uploadFile.getPath(), uploadFile.getName()), // attachment URL 전달 fileUrlPortIn.getAttachment( - uploadFile.getType().getFileStorageType(), uploadFile.getId()))); + FileStorageType.valueOf(uploadStorageType), uploadFile.getId()))); } } diff --git a/core/src/main/java/app/module/core/usecase/file/saveToStorage/ports/application/SaveToStorageService.java b/core/src/main/java/app/module/core/usecase/file/saveToStorage/ports/application/SaveToStorageService.java index 6c342b6d..39d13b2c 100644 --- a/core/src/main/java/app/module/core/usecase/file/saveToStorage/ports/application/SaveToStorageService.java +++ b/core/src/main/java/app/module/core/usecase/file/saveToStorage/ports/application/SaveToStorageService.java @@ -20,6 +20,7 @@ import java.util.Set; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.apache.tika.Tika; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -30,6 +31,8 @@ public class SaveToStorageService implements SaveToStoragePortIn { private final MessageUtil messageUtil; private final Tika tika; private final Set fileUploadStrategies; + @Value("${path.upload.storage}") + private String uploadStorageType; @Override public Optional operate(FileUploadType fileUploadType, @@ -45,7 +48,7 @@ public class SaveToStorageService implements SaveToStoragePortIn { String subPath = getDirPath(fileUploadType.getSubPath()); String createFilename = getUUIDFilename(getFileExtension(originalFilename).orElse(null)); - getFileUploadStrategy(fileUploadType.getFileStorageType()) + getFileUploadStrategy(FileStorageType.valueOf(uploadStorageType)) .operate(multipartFile, subPath, createFilename); return Optional.of( @@ -128,6 +131,6 @@ public class SaveToStorageService implements SaveToStoragePortIn { () -> new NoSuchElementException( String.format("No file upload strategy found: %s", - fileStorageType.name()))); + fileStorageType.getName()))); } } diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileDao.java b/core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileDao.java new file mode 100644 index 00000000..f8786198 --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileDao.java @@ -0,0 +1,66 @@ +package app.module.core.usecase.file.updateFile.adapters.persistence; + +import app.module.core.config.adapters.persistence.entity.UploadFile; +import app.module.core.config.application.annotation.DeleteCommand; +import app.module.core.config.application.annotation.UpdateCommand; +import app.module.core.config.application.enums.FileUploadType; +import app.module.core.config.application.util.CommonUtil; +import app.module.core.config.application.util.SftpFileDeleteUtil; +import app.module.core.usecase.file.createFile.ports.CreateFilePortOut; +import app.module.core.usecase.file.createFile.ports.application.domain.CreateFile; +import app.module.core.usecase.file.createFile.ports.application.domain.CreateFileCmd; +import app.module.core.usecase.file.updateFile.ports.UpdateFilePortOut; +import app.module.core.usecase.file.updateFile.ports.application.domain.UpdateFileCmd; +import app.module.core.usecase.file.updateFile.ports.application.domain.UpdateUploadFileParam; +import app.module.core.usecase.file.updateFile.ports.application.domain.UploadFileDto; +import app.module.core.usecase.file.url.application.port.in.FileUrlPortIn; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.SftpException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +@Slf4j +@Repository +@RequiredArgsConstructor +class UpdateFileDao implements UpdateFilePortOut { + private final UpdateFileMapper mapper; + private final SftpFileDeleteUtil sftpFileDeleteUtil; + + @Override + @DeleteCommand + public void operate(UpdateFileCmd command) { + + List deletedFileList = mapper.findDeleteFileList(new UpdateUploadFileParam( + command.getId(), + command.getFileMappingIds(), + command.getType().getName() + )); + + for (UploadFileDto file : deletedFileList) { + try { + sftpFileDeleteUtil.deleteRealFile(file); + } catch (JSchException | SftpException e) { + log.error("Failed to delete file from SFTP for mapping ID {}: {}", file.getId(), e.getMessage(), e); + throw new RuntimeException("Failed to delete file from SFTP", e); + } catch (Exception e) { + 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( + new UpdateUploadFileParam( + command.getId(), + deletedFileList.stream().map(UploadFileDto::getId).toList(), + command.getType().getName())); + } + + command.getFileMappingIds().forEach(fileId -> mapper.updateFile(new UploadFileDto(fileId, command.getId(),command.getType().getName()))); + } + +} diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileMapper.java b/core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileMapper.java new file mode 100644 index 00000000..eaa74f02 --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/adapters/persistence/UpdateFileMapper.java @@ -0,0 +1,14 @@ +package app.module.core.usecase.file.updateFile.adapters.persistence; + +import app.module.core.usecase.file.updateFile.ports.application.domain.UpdateUploadFileParam; +import app.module.core.usecase.file.updateFile.ports.application.domain.UploadFileDto; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface UpdateFileMapper { + List findDeleteFileList(UpdateUploadFileParam uploadFile); + void deleteFile(UpdateUploadFileParam uploadFile); + void updateFile(UploadFileDto uploadFile); +} diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortIn.java b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortIn.java new file mode 100644 index 00000000..60736667 --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortIn.java @@ -0,0 +1,8 @@ +package app.module.core.usecase.file.updateFile.ports; + +import app.module.core.usecase.file.updateFile.ports.application.domain.UpdateFileCmd; + + +public interface UpdateFilePortIn { + void operate(UpdateFileCmd command); +} \ No newline at end of file diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortOut.java b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortOut.java new file mode 100644 index 00000000..77af4353 --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/UpdateFilePortOut.java @@ -0,0 +1,8 @@ +package app.module.core.usecase.file.updateFile.ports; + +import app.module.core.usecase.file.updateFile.ports.application.domain.UpdateFileCmd; + + +public interface UpdateFilePortOut { + void operate(UpdateFileCmd command); +} \ No newline at end of file diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/UpdateFileService.java b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/UpdateFileService.java new file mode 100644 index 00000000..36363d22 --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/UpdateFileService.java @@ -0,0 +1,20 @@ +package app.module.core.usecase.file.updateFile.ports.application; + +import app.module.core.usecase.file.updateFile.ports.UpdateFilePortIn; +import app.module.core.usecase.file.updateFile.ports.UpdateFilePortOut; +import app.module.core.usecase.file.updateFile.ports.application.domain.UpdateFileCmd; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + + +@Service +@RequiredArgsConstructor +class UpdateFileService implements UpdateFilePortIn { + + private final UpdateFilePortOut portOut; + + @Override + public void operate(UpdateFileCmd command) { + portOut.operate(command); + } +} \ No newline at end of file diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateFileCmd.java b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateFileCmd.java new file mode 100644 index 00000000..781f81e0 --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateFileCmd.java @@ -0,0 +1,19 @@ +package app.module.core.usecase.file.updateFile.ports.application.domain; + +import app.module.core.config.application.enums.FileUploadType; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@EqualsAndHashCode +public class UpdateFileCmd { + private Long id; + private List fileMappingIds; + private FileUploadType type; +} diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateUploadFileParam.java b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateUploadFileParam.java new file mode 100644 index 00000000..283c1b2f --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UpdateUploadFileParam.java @@ -0,0 +1,18 @@ +package app.module.core.usecase.file.updateFile.ports.application.domain; + +import app.module.core.config.adapters.persistence.component.AuditCommand; +import app.module.core.config.application.enums.FileUploadType; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Setter +@Getter +@AllArgsConstructor +public class UpdateUploadFileParam extends AuditCommand { + private Long id; + private List fileMappingIds; + private String type; +} diff --git a/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UploadFileDto.java b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UploadFileDto.java new file mode 100644 index 00000000..dcdcfd0b --- /dev/null +++ b/core/src/main/java/app/module/core/usecase/file/updateFile/ports/application/domain/UploadFileDto.java @@ -0,0 +1,43 @@ +package app.module.core.usecase.file.updateFile.ports.application.domain; + +import app.module.core.config.adapters.persistence.component.AuditCommand; +import app.module.core.config.adapters.persistence.component.AuditEntity; +import app.module.core.config.application.enums.FileUploadType; +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class UploadFileDto extends AuditCommand { + + private Long id; + + private Long mappingId; + + private String type; + + private String path; + + private String name; + + private String originName; + + private Long fileLength; + + private LocalDateTime updatedAt; + + private String updatedBy; + + public UploadFileDto(Long id) { + this.id = id; + } + + public UploadFileDto(Long id, Long mappingId, String type) { + this.id = id; + this.mappingId = mappingId; + this.type = type; + } +} diff --git a/core/src/main/java/app/module/core/usecase/getAttachment/adapters/web/GetAttachmentController.java b/core/src/main/java/app/module/core/usecase/getAttachment/adapters/web/GetAttachmentController.java index 12afde26..8a27bab1 100644 --- a/core/src/main/java/app/module/core/usecase/getAttachment/adapters/web/GetAttachmentController.java +++ b/core/src/main/java/app/module/core/usecase/getAttachment/adapters/web/GetAttachmentController.java @@ -1,5 +1,6 @@ package app.module.core.usecase.getAttachment.adapters.web; +import app.module.core.config.application.enums.FileStorageType; 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; @@ -27,6 +28,8 @@ class GetAttachmentController { private String cloudFrontDomain; @Value("${app.aws.s3.bucketFolder:null}") private String bucketFolder; + @Value("${path.upload.storage}") + private String uploadStorageType; @GetMapping(path = "/content-disposition/attachment/{fileId}") ResponseEntity operate(@PathVariable Long fileId) throws MalformedURLException { @@ -55,7 +58,7 @@ class GetAttachmentController { UrlResource resource = null; - switch (getFile.getType().getFileStorageType()) { + switch (FileStorageType.valueOf(uploadStorageType)) { case LOCAL: String filePath = Paths.get(publicPath, getFile.getPath(), getFile.getName()) diff --git a/core/src/main/java/app/module/core/usecase/uri/save/ports/application/URISaveService.java b/core/src/main/java/app/module/core/usecase/uri/save/ports/application/URISaveService.java index ab79e355..c95d68b1 100644 --- a/core/src/main/java/app/module/core/usecase/uri/save/ports/application/URISaveService.java +++ b/core/src/main/java/app/module/core/usecase/uri/save/ports/application/URISaveService.java @@ -1,5 +1,6 @@ package app.module.core.usecase.uri.save.ports.application; +import app.module.core.config.application.enums.FileStorageType; import app.module.core.config.application.enums.FileUploadType; import app.module.core.config.application.exception.AlreadyExistItemException; import app.module.core.config.application.util.MessageUtil; @@ -11,6 +12,7 @@ import app.module.core.usecase.uri.save.ports.URISavePortIn; import app.module.core.usecase.uri.save.ports.URISavePortOut; import app.module.core.usecase.uri.save.ports.application.domain.URISaveCommand; import app.module.core.usecase.uri.view.ports.URIViewPortIn; +import org.springframework.beans.factory.annotation.Value; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import lombok.RequiredArgsConstructor; @@ -28,6 +30,8 @@ class URISaveService implements URISavePortIn { private final MessageUtil messageUtil; private final SaveToStoragePortIn saveToStoragePortIn; private final FileUrlPortIn fileUrlPortIn; + @Value("${path.upload.storage}") + private String uploadStorageType; @Transactional @CacheEvict( @@ -59,7 +63,7 @@ class URISaveService implements URISavePortIn { uri.setOgImage( fileUrlPortIn.getInline( - ogImg.getType().getFileStorageType(), ogImg.getPath(), ogImg.getName())); + FileStorageType.valueOf(uploadStorageType), ogImg.getPath(), ogImg.getName())); } return uriSavePortOut.connect(uri); diff --git a/core/src/main/java/app/module/core/usecase/user/findUser/ports/application/FindUserService.java b/core/src/main/java/app/module/core/usecase/user/findUser/ports/application/FindUserService.java index 0d71c29d..07ce74d9 100644 --- a/core/src/main/java/app/module/core/usecase/user/findUser/ports/application/FindUserService.java +++ b/core/src/main/java/app/module/core/usecase/user/findUser/ports/application/FindUserService.java @@ -1,5 +1,6 @@ package app.module.core.usecase.user.findUser.ports.application; +import app.module.core.config.application.enums.FileStorageType; import app.module.core.usecase.file.url.application.port.in.FileUrlPortIn; import app.module.core.usecase.user.findUser.ports.FindUserPortIn; import app.module.core.usecase.user.findUser.ports.FindUserPortOut; @@ -8,6 +9,7 @@ import app.module.core.usecase.user.findUser.ports.application.domain.FindUser; import app.module.core.usecase.user.findUser.ports.application.domain.FindUserCmd; import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service @@ -17,6 +19,9 @@ class FindUserService implements FindUserPortIn { private final FindUserPortOut portOut; private final FileUrlPortIn fileUrlPortIn; + @Value("${path.upload.storage}") + private String uploadStorageType; + @Override public Optional operate(FindUserCmd command) { return portOut @@ -29,14 +34,14 @@ class FindUserService implements FindUserPortIn { // 참조 URL 전달 profileImg.setReferURL( fileUrlPortIn.getInline( - profileImg.getType().getFileStorageType(), + FileStorageType.valueOf(uploadStorageType), profileImg.getPath(), profileImg.getName())); // attachment URL 전달 profileImg.setAttachmentURL( fileUrlPortIn.getAttachment( - profileImg.getType().getFileStorageType(), profileImg.getId())); + FileStorageType.valueOf(uploadStorageType), profileImg.getId())); } return Optional.of(findUser); diff --git a/core/src/main/resources/mappers/file/UpdateFileMapper.xml b/core/src/main/resources/mappers/file/UpdateFileMapper.xml new file mode 100644 index 00000000..86cc300e --- /dev/null +++ b/core/src/main/resources/mappers/file/UpdateFileMapper.xml @@ -0,0 +1,47 @@ + + + + + + + + UPDATE upload_file + SET + + WHERE type = #{type} and mapping_id = #{id} and is_deleted = false + + and id IN ( + + #{fileId} + + ) + + + + + UPDATE upload_file + SET mapping_id = #{mappingId}, + type = #{type}, + + WHERE id = #{id} + + + \ No newline at end of file diff --git a/core/src/main/resources/sql/schema/02_create-all.sql b/core/src/main/resources/sql/schema/02_create-all.sql index c033ef94..dfd380d3 100644 --- a/core/src/main/resources/sql/schema/02_create-all.sql +++ b/core/src/main/resources/sql/schema/02_create-all.sql @@ -83,7 +83,8 @@ COMMENT ON COLUMN role.is_deleted IS '삭제 여부'; CREATE SEQUENCE upload_file_seq START WITH 1 INCREMENT BY 1 CACHE 1 NO CYCLE; CREATE TABLE upload_file ( - id bigint DEFAULT nextval('upload_file_seq') NOT NULL, -- 파일 ID (PK) + id int8 DEFAULT nextval('upload_file_seq') NOT NULL, -- 파일 ID (PK) + mapping_id int8, -- 파일 매핑 ID name varchar(255), -- 시스템 저장 파일명 origin_name varchar(255), -- 원본 파일명 path varchar(255), -- 파일 경로 @@ -115,6 +116,7 @@ CREATE TABLE upload_file ( COMMENT ON TABLE upload_file IS '업로드 파일 정보 테이블'; COMMENT ON COLUMN upload_file.id IS '파일 ID (PK)'; +COMMENT ON COLUMN upload_file.mapping_id IS '파일 매핑 ID'; COMMENT ON COLUMN upload_file.name IS '시스템 저장 파일명'; COMMENT ON COLUMN upload_file.origin_name IS '원본 파일명'; COMMENT ON COLUMN upload_file.path IS '파일 경로'; @@ -1865,37 +1867,6 @@ COMMENT ON COLUMN notice.is_deleted IS '삭제여부'; --- ============================================ --- TABLE : notice_has_upload_file --- DESC : 공지사항 파일 매핑 테이블 --- ============================================ -CREATE TABLE notice_has_upload_file ( - upload_files_id bigint NOT NULL, -- 업로드 파일 ID (FK) - notice_id varchar(255) NOT NULL, -- 공지사항 ID (FK) - created_at timestamp(6), -- 생성일 - created_by varchar(255), -- 생성자 - updated_at timestamp(6), -- 수정일 - updated_by varchar(255), -- 수정자 - deleted_at timestamp(6), -- 삭제일 - deleted_by varchar(255), -- 삭제자 - is_deleted boolean DEFAULT false NOT NULL -- 삭제 여부 -); - -ALTER TABLE notice_has_upload_file ADD CONSTRAINT fk_notice_has_upload_file__notice FOREIGN KEY (notice_id) REFERENCES notice(id); -ALTER TABLE notice_has_upload_file ADD CONSTRAINT fk_notice_has_upload_file__upload_file FOREIGN KEY (upload_files_id) REFERENCES upload_file(id); - -COMMENT ON TABLE notice_has_upload_file IS '공지사항 파일 매핑 테이블'; - -COMMENT ON COLUMN notice_has_upload_file.upload_files_id IS '업로드 파일 ID'; -COMMENT ON COLUMN notice_has_upload_file.notice_id IS '공지사항 ID'; -COMMENT ON COLUMN notice_has_upload_file.created_at IS '생성일'; -COMMENT ON COLUMN notice_has_upload_file.created_by IS '생성자'; -COMMENT ON COLUMN notice_has_upload_file.updated_at IS '수정일'; -COMMENT ON COLUMN notice_has_upload_file.updated_by IS '수정자'; -COMMENT ON COLUMN notice_has_upload_file.deleted_at IS '삭제일'; -COMMENT ON COLUMN notice_has_upload_file.deleted_by IS '삭제자'; -COMMENT ON COLUMN notice_has_upload_file.is_deleted IS '삭제여부'; - -- ============================================
아이디