From e53572f2e0d0ad287324e320f784960f6f5a4baa Mon Sep 17 00:00:00 2001 From: haeri Date: Tue, 14 Nov 2023 12:53:56 +0000 Subject: [PATCH] =?UTF-8?q?Chore=20:=20=EC=B5=9C=EC=A2=85=ED=99=95?= =?UTF-8?q?=EC=9D=B8=EC=84=9C=20entity=20=EC=88=98=EC=A0=95,=20=EC=B5=9C?= =?UTF-8?q?=EC=A2=85=20=EC=8A=B9=EC=9D=B8,=20userSeq=EB=A1=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nw/controller/FinaldocsController.java | 23 ++++ .../lab/cherry/nw/model/FinaldocsEntity.java | 110 +++++++++++------- .../nw/repository/FinaldocsRepository.java | 11 +- .../cherry/nw/service/FinaldocsService.java | 12 +- .../service/Impl/FinalTemplServiceImpl.java | 3 +- .../nw/service/Impl/FinaldocsServiceImpl.java | 80 ++++++------- .../nw/service/Impl/UserCardServiceImpl.java | 2 + 7 files changed, 152 insertions(+), 89 deletions(-) diff --git a/nw/src/main/java/lab/cherry/nw/controller/FinaldocsController.java b/nw/src/main/java/lab/cherry/nw/controller/FinaldocsController.java index a320f28..c2b4247 100644 --- a/nw/src/main/java/lab/cherry/nw/controller/FinaldocsController.java +++ b/nw/src/main/java/lab/cherry/nw/controller/FinaldocsController.java @@ -1,5 +1,6 @@ package lab.cherry.nw.controller; +import org.bson.types.ObjectId; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -156,6 +157,28 @@ public ResponseEntity findById(@PathVariable("id") String id) { return new ResponseEntity<>(finaldocsService.findById(id), new HttpHeaders(), HttpStatus.OK); } + /** + * [FinaldocsController] 특정 최종확인서 조회 함수 + * + * @param id 최종확인서 고유번호를 입력합니다. + * @return + *
+     * true  : 특정 최종확인서 정보를 반환합니다.
+     * false : 에러(400, 404)를 반환합니다.
+     * 
+ * + * Author : hhhaeri(yhoo0020@gmail.com) + */ + @GetMapping("/user/{userid}") + @Operation(summary = "User Id 로 최종확인서 찾기", description = "최종확인서를 조회합니다.") + public ResponseEntity findByUserId(@PathVariable("userid") String userid) { + + log.info("[FinaldocsController] findByFinaldocsId... with userId", userid); + + return new ResponseEntity<>(finaldocsService.findByUserId(userid), new HttpHeaders(), HttpStatus.OK); + } + + /** * [FinaldocsController] 특정 최종확인서 삭제 함수 * diff --git a/nw/src/main/java/lab/cherry/nw/model/FinaldocsEntity.java b/nw/src/main/java/lab/cherry/nw/model/FinaldocsEntity.java index 0ef4f54..b6b2916 100644 --- a/nw/src/main/java/lab/cherry/nw/model/FinaldocsEntity.java +++ b/nw/src/main/java/lab/cherry/nw/model/FinaldocsEntity.java @@ -18,7 +18,6 @@ import java.io.Serializable; import java.time.Instant; import java.util.List; -import java.util.Map; /** *
@@ -40,33 +39,37 @@ public class FinaldocsEntity implements Serializable {
     @Schema(title = "최종확인서 고유번호", example = "64ed89aa9e813b5ab16da6de")
     private String id;
 
-	@NotNull
-    @JsonProperty("finaltempl")
-    @Schema(title = "최종확인서 템플릿 정보", example = "64ed89aa9e813b5ab16da6de")
-    private FinalTemplEntity finaltempl;
-
-	@NotNull
     @DBRef
     @JsonProperty("user")
-    @Schema(title = "사용자 정보", example = "64ed89aa9e813b5ab16da6de")
+    @Schema(title = "유저 정보") // (Long) Tsid
     private UserEntity user;
 
-	@NotNull
     @DBRef
     @JsonProperty("org")
-    @Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
+    @Schema(title = "조직 정보") // (Long) Tsid
     private OrgEntity org;
 
-	@NotNull
-    @JsonProperty("finaldocsName")
-	@Schema(title = "최종확인서 이름", example = "11시 그랜드 최종 확인서")
-	@Size(min = 4, max = 255, message = "Minimum name length: 4 characters")
-    private String name;
+    @DBRef
+	@JsonProperty("finaltempl")
+	@Schema(title = "최종확인서 템플릿 정보", example = "64ed89aa9e813b5ab16da6de")
+    private  FinalTemplEntity finaltempl;
 
     @JsonProperty("content")
     @Schema(title = "최종확인서 내용", example = "")
     private List content;
 
+    @DBRef
+    @JsonProperty("org_approver")
+    @Schema(title = "업체 확인자 정보",type="String",example = "38352658567418867")
+    private UserEntity org_approver;
+
+    @JsonProperty("org_confirm")
+    @Schema(title = "업체 확인", type="Boolean", example = "false")
+    private boolean org_confirm;
+
+    @JsonProperty("client_confirm")
+	@Schema(title = "신랑신부 확인", type="Boolean", example = "false")
+	private boolean client_confirm;
 
     @JsonProperty("updated_at")
     @JsonFormat(pattern="yyyy-MM-dd hh:mm:ss", locale = "ko_KR", timezone = "Asia/Seoul")
@@ -78,6 +81,21 @@ public class FinaldocsEntity implements Serializable {
     @Schema(title = "최종확인서 생성 시간", example = "2023-07-04 12:00:00")
     private Instant createdAt;
 
+//////////////////////////////////////////////////////////////////////////
+
+@Getter
+@Builder
+@NoArgsConstructor @AllArgsConstructor
+public static class FinaldocsFinalConfirm {
+    @Schema(title = "업체 확인자 정보", type="String", example = "38352658567418867")
+    private String org_approver;
+
+    @Schema(title = "업체 확인", type="Boolean", example = "false")
+    private boolean org_confirm;
+
+    @Schema(title = "신랑신부 확인", type="Boolean", example = "false")
+    private boolean client_confirm;
+}
 
 //////////////////////////////////////////////////////////////////////////
 
@@ -86,31 +104,33 @@ public class FinaldocsEntity implements Serializable {
     @NoArgsConstructor @AllArgsConstructor
     public static class FinaldocsCreateDto {
 
-		@NotBlank
-        @Schema(title = "최종확인서 이름", example = "11시 그랜드 최종 확인서")
-        @Size(min = 4, max = 255, message = "Minimum name length: 4 characters")
-        private String name;
+		// @NotBlank
+        // @Schema(title = "최종확인서 이름", example = "11시 그랜드 최종 확인서")
+        // @Size(min = 4, max = 255, message = "Minimum name length: 4 characters")
+        // private String name;
+
+		@Schema(title = "사용자 고유번호", example = "64ed89aa9e813b5ab16da6de")
+        private String userSeq;
 
-		@NotBlank
-		@JsonProperty("user")
-		@Schema(title = "사용자 정보", example = "64ed89aa9e813b5ab16da6de")
-        private String user;
+		@Schema(title = "조직 고유번호", example = "64ed89aa9e813b5ab16da6de")
+        private String orgSeq;
 
-		@NotBlank
-		@JsonProperty("org")
-		@Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
-        private String org;
+		@Schema(title = "최종확인서 템플릿 고유번호", example = "64ed89aa9e813b5ab16da6de")
+        private  String finaltemplSeq;
 
-		@NotBlank
-		@JsonProperty("finaltempl")
-		@Schema(title = "최종확인서 템플릿 정보", example = "64ed89aa9e813b5ab16da6de")
-        private  String finaltempl;
 
-//		@NotBlank
-		@JsonProperty("content")
 		@Schema(title = "최종확인서 내용", example = "")
         private List content;
 
+        @Schema(title = "업체 확인자 정보",type="String",example = "38352658567418867")
+        private String org_approverSeq;
+
+        @Schema(title = "업체 확인", type="Boolean", example = "false")
+        private boolean org_confirm;
+
+		@Schema(title = "신랑신부 확인", type="Boolean", example = "false")
+		private boolean client_confirm;
+
 
     }
 
@@ -120,21 +140,27 @@ public static class FinaldocsCreateDto {
     @NoArgsConstructor @AllArgsConstructor
     public static class FinaldocsUpdateDto {
 
-		@Schema(title = "최종확인서 고유번호", example = "64ed89aa9e813b5ab16da6de")
-        private String id;
-
-		@Schema(title = "최종확인서 템플릿 정보", example = "64ed89aa9e813b5ab16da6de")
-        private String finaltempl;
+		@Schema(title = "최종확인서 템플릿 고유번호", example = "64ed89aa9e813b5ab16da6de")
+        private String finaltemplSeq;
 
-		@Schema(title = "사용자 정보", example = "64ed89aa9e813b5ab16da6de")
-        private String user;
+		@Schema(title = "사용자 고유번호", example = "64ed89aa9e813b5ab16da6de")
+        private String userSeq;
 
-		@Schema(title = "조직 정보", example = "64ed89aa9e813b5ab16da6de")
-        private String org;
+		@Schema(title = "조직 고유번호", example = "64ed89aa9e813b5ab16da6de")
+        private String orgSeq;
 
 		@Schema(title = "최종확인서 내용", example = "")
         private List content;
 
+        @Schema(title = "업체 확인자 정보",type="String",example = "38352658567418867")
+        private String org_approverSeq;
+
+        @Schema(title = "업체 확인", type="Boolean", example = "false")
+        private boolean org_confirm;
+
+		@Schema(title = "신랑신부 확인", type="Boolean", example = "false")
+		private boolean client_confirm;
+
 
     }
 }
diff --git a/nw/src/main/java/lab/cherry/nw/repository/FinaldocsRepository.java b/nw/src/main/java/lab/cherry/nw/repository/FinaldocsRepository.java
index db27d50..8a6ed09 100644
--- a/nw/src/main/java/lab/cherry/nw/repository/FinaldocsRepository.java
+++ b/nw/src/main/java/lab/cherry/nw/repository/FinaldocsRepository.java
@@ -3,10 +3,14 @@
 import java.time.Instant;
 import java.util.List;
 import java.util.Optional;
+import org.bson.types.ObjectId;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.data.mongodb.repository.Query;
+import lab.cherry.nw.model.BookmarkEntity;
 import lab.cherry.nw.model.FinaldocsEntity;
+import lab.cherry.nw.model.UserCardEntity;
 
 
 /**
@@ -22,14 +26,17 @@ public interface FinaldocsRepository extends MongoRepository findAll(Pageable pageable);
 
-    Page findPageByName(String finaldocsName, Pageable pageable);
+    // Page findPageByName(String finaldocsName, Pageable pageable);
 
     Page findPageById(String id, Pageable pageable);
 
     Optional findById(String id);
 
-    Optional findByName(String finaldocsName);
+    // Optional findByName(String finaldocsName);
 
 	List findAllBycreatedAtBetween(Instant start, Instant end);
 
+    @Query("{'user.$_id' : ?0}")
+    Optional findByUserid(String userid);
+  
 }
\ No newline at end of file
diff --git a/nw/src/main/java/lab/cherry/nw/service/FinaldocsService.java b/nw/src/main/java/lab/cherry/nw/service/FinaldocsService.java
index 9fb0964..cf420ef 100644
--- a/nw/src/main/java/lab/cherry/nw/service/FinaldocsService.java
+++ b/nw/src/main/java/lab/cherry/nw/service/FinaldocsService.java
@@ -1,9 +1,13 @@
 package lab.cherry.nw.service;
 
+import java.util.Optional;
+import org.bson.types.ObjectId;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Component;
+import lab.cherry.nw.model.BookmarkEntity;
 import lab.cherry.nw.model.FinaldocsEntity;
+import lab.cherry.nw.model.UserCardEntity;
 
 /**
  * 
@@ -17,11 +21,11 @@
 public interface FinaldocsService {
     Page getFinaldocs(Pageable pageable);
     FinaldocsEntity createFinaldocs(FinaldocsEntity.FinaldocsCreateDto finaldocsCreateDto);
-    void updateById(String id, FinaldocsEntity.FinaldocsUpdateDto finaldocs);
+    void updateById(String id, FinaldocsEntity.FinaldocsUpdateDto finaldocsUpdateDto);
     FinaldocsEntity findById(String id);
-    FinaldocsEntity findByName(String name);
+    FinaldocsEntity findByUserId(String userId);
+    // FinaldocsEntity findByName(String name);
     void deleteById(String id);
-    Boolean Approval(Boolean Yn);
-    Page findPageByName(String name, Pageable pageable);
+    // Page findPageByName(String name, Pageable pageable);
     Page findPageById(String id, Pageable pageable);
 }
diff --git a/nw/src/main/java/lab/cherry/nw/service/Impl/FinalTemplServiceImpl.java b/nw/src/main/java/lab/cherry/nw/service/Impl/FinalTemplServiceImpl.java
index 7c35911..e48a320 100644
--- a/nw/src/main/java/lab/cherry/nw/service/Impl/FinalTemplServiceImpl.java
+++ b/nw/src/main/java/lab/cherry/nw/service/Impl/FinalTemplServiceImpl.java
@@ -140,7 +140,7 @@ public void deleteById(String id) {
 
 
     /**
-     * [FinalTemplServiceImpl] ID로 최종확인서 템플릿  조회 함수
+     * [FinalTemplServiceImpl] ID로 최종확인서 템플릿 조회 함수
      *
      * @param id 조회할 최종확인서 템플릿의 식별자입니다.
      * @return 주어진 식별자에 해당하는 조직 정보
@@ -156,7 +156,6 @@ public void deleteById(String id) {
 //        return finaldocsRepository.findByName(name).orElseThrow(() -> new EntityNotFoundException("Fianldocs with Id " + name + " Not Found."));
 //    }
 
-
     @Transactional(readOnly = true)
     public FinalTemplEntity findById(String id) {
         return finalTemplRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("finalTempl with Id " + id + " Not Found."));
diff --git a/nw/src/main/java/lab/cherry/nw/service/Impl/FinaldocsServiceImpl.java b/nw/src/main/java/lab/cherry/nw/service/Impl/FinaldocsServiceImpl.java
index b411166..4290642 100644
--- a/nw/src/main/java/lab/cherry/nw/service/Impl/FinaldocsServiceImpl.java
+++ b/nw/src/main/java/lab/cherry/nw/service/Impl/FinaldocsServiceImpl.java
@@ -4,8 +4,10 @@
 import lab.cherry.nw.error.exception.CustomException;
 import lab.cherry.nw.error.exception.EntityNotFoundException;
 import lab.cherry.nw.model.FinaldocsEntity;
+import lab.cherry.nw.model.BookmarkEntity;
 import lab.cherry.nw.model.FinalTemplEntity;
 import lab.cherry.nw.model.OrgEntity;
+import lab.cherry.nw.model.UserCardEntity;
 import lab.cherry.nw.model.UserEntity;
 import lab.cherry.nw.repository.FinaldocsRepository;
 import lab.cherry.nw.service.FinalTemplService;
@@ -14,12 +16,14 @@
 import lab.cherry.nw.service.UserService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.bson.types.ObjectId;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.Instant;
+import java.util.Optional;
 
 /**
  * 
@@ -73,12 +77,11 @@ public FinaldocsEntity createFinaldocs(FinaldocsEntity.FinaldocsCreateDto finald
 
         Instant instant = Instant.now();
 
-        UserEntity userEntity = userService.findById(finaldocsCreateDto.getUser());
-        OrgEntity orgEntity = orgService.findById(finaldocsCreateDto.getOrg());
-        FinalTemplEntity finamTemplEntity = finalTemplService.findById(finaldocsCreateDto.getFinaltempl());
+        UserEntity userEntity = userService.findById(finaldocsCreateDto.getUserSeq());
+        OrgEntity orgEntity = orgService.findById(finaldocsCreateDto.getOrgSeq());
+        FinalTemplEntity finamTemplEntity = finalTemplService.findById(finaldocsCreateDto.getFinaltemplSeq());
 
         FinaldocsEntity finaldocsEntity = FinaldocsEntity.builder()
-            .name(finaldocsCreateDto.getName())
             .content(finaldocsCreateDto.getContent())
             .user(userEntity)
             .org(orgEntity)
@@ -100,23 +103,39 @@ public FinaldocsEntity createFinaldocs(FinaldocsEntity.FinaldocsCreateDto finald
      *
      * Author : hhhaeri(yhoo0020@gmail.com)
      */
-    public void updateById(String id, FinaldocsEntity.FinaldocsUpdateDto finaldocs) {
+    public void updateById(String id, FinaldocsEntity.FinaldocsUpdateDto finaldocsUpdateDto) {
 
         FinaldocsEntity finaldocsEntity = findById(id);
-        UserEntity userEntity = userService.findById(finaldocs.getUser());
-        OrgEntity orgEntity = orgService.findById(finaldocs.getOrg());
-        FinalTemplEntity finamTemplEntity = finalTemplService.findById(finaldocs.getFinaltempl());
+        UserEntity userEntity = userService.findById(finaldocsUpdateDto.getUserSeq());
+        OrgEntity orgEntity = orgService.findById(finaldocsUpdateDto.getOrgSeq());
+        FinalTemplEntity finamTemplEntity = finalTemplService.findById(finaldocsUpdateDto.getFinaltemplSeq());
+        UserEntity orgUserEntity = finaldocsEntity.getOrg_approver();
 
         Instant instant = Instant.now();
 
-        if (finaldocs.getContent() != null) {
+        if (finaldocsUpdateDto.getContent() != null) {   
+            
+            if (finaldocsUpdateDto.getOrgSeq() != null){
+				orgEntity = orgService.findById(finaldocsUpdateDto.getOrgSeq());
+			}
+			if (finaldocsUpdateDto.isOrg_confirm()){
+                if(finaldocsUpdateDto.getOrg_approverSeq()!=null){
+                    orgUserEntity = userService.findById(finaldocsUpdateDto.getOrg_approverSeq());
+                }else{
+                log.error("[FinaldocsServiceImpl - udpateFinaldocs] org_approver와 isOrg_confirm 입력이 잘못되었습니다.");
+                throw new CustomException(ErrorCode.INVALID_INPUT_VALUE);
+                }
+                
+            }
 
             finaldocsEntity = FinaldocsEntity.builder()
-                    .id(finaldocsEntity.getId())
                     .user(userEntity)
                     .org(orgEntity)
                     .finaltempl(finamTemplEntity)
-                    .content((finaldocs.getContent() != null) ? finaldocs.getContent() : finaldocsEntity.getContent())
+                    .org_approver(orgUserEntity)
+                    .org_confirm(finaldocsUpdateDto.isOrg_confirm()==!(finaldocsEntity.isOrg_confirm())?finaldocsUpdateDto.isOrg_confirm():finaldocsEntity.isOrg_confirm())
+                    .client_confirm(finaldocsUpdateDto.isClient_confirm()==!(finaldocsEntity.isClient_confirm())?finaldocsUpdateDto.isClient_confirm():finaldocsEntity.isClient_confirm())
+                    .content((finaldocsUpdateDto.getContent() != null) ? finaldocsUpdateDto.getContent() : finaldocsEntity.getContent())
                     .updated_at(instant)
                     .build();
 
@@ -144,27 +163,6 @@ public void deleteById(String id) {
     }
 
 
-  /**
-     * [FinaldocsServiceImpl] 최종확인서 승인 함수
-     *
-     * @param name 조회할 최종확인서의 이름입니다.
-     * @return 주어진 이름에 해당하는 최종확인서 정보를 리턴합니다.
-     * @throws EntityNotFoundException 해당 이름의 최종확인서 정보가 없을 경우 예외 처리 발생
-     * 
-     * 입력한 name에 해당하는 최종확인서 정보를 조회합니다.
-     * 
- * - * Author : hhhaeri(yhoo0020@gmail.com) - */ - @Transactional(readOnly = true) - @Override - public Boolean Approval(Boolean Yn) { - if(Yn ==true){ - return true; - }else{ - return false; - } - } /** * [FinaldocsServiceImpl] ID로 최종확인서 조회 함수 * @@ -200,17 +198,21 @@ public FinaldocsEntity findById(String id) { * * Author : hhhaeri(yhoo0020@gmail.com) */ - @Transactional(readOnly = true) - public FinaldocsEntity findByName(String name) { - return finaldocsRepository.findByName(name).orElseThrow(() -> new EntityNotFoundException("Org with Name " + name + " Not Found.")); - } + // @Transactional(readOnly = true) + // public FinaldocsEntity findByName(String name) { + // return finaldocsRepository.findByName(name).orElseThrow(() -> new EntityNotFoundException("Org with Name " + name + " Not Found.")); + // } + + // @Transactional(readOnly = true) + // public Page findPageByName(String name, Pageable pageable) { + // return finaldocsRepository.findPageByName(name, pageable); + // } @Transactional(readOnly = true) - public Page findPageByName(String name, Pageable pageable) { - return finaldocsRepository.findPageByName(name, pageable); + public FinaldocsEntity findByUserId(String userId) { + return finaldocsRepository.findByUserid(userId).orElseThrow(() -> new EntityNotFoundException("FinaldocsEntity with User id " + userId.toString() + " Not Found.")); } - @Transactional(readOnly = true) public Page findPageById(String id, Pageable pageable) { return finaldocsRepository.findPageById(id, pageable); diff --git a/nw/src/main/java/lab/cherry/nw/service/Impl/UserCardServiceImpl.java b/nw/src/main/java/lab/cherry/nw/service/Impl/UserCardServiceImpl.java index 160148b..a642c39 100644 --- a/nw/src/main/java/lab/cherry/nw/service/Impl/UserCardServiceImpl.java +++ b/nw/src/main/java/lab/cherry/nw/service/Impl/UserCardServiceImpl.java @@ -235,6 +235,7 @@ public Page findPageById(String name, Pageable pageable) { return userCardRepository.findPageById(name, pageable); } + // 사용자ID로 usercard 중복 체크 @Transactional(readOnly = true) public void checkExistsWithUserId(String userid) { if (userCardRepository.findByUserSeq(userid).isPresent()) { @@ -242,4 +243,5 @@ public void checkExistsWithUserId(String userid) { } } + }