Parcourir la source

jpa continue ...........

shjung il y a 3 ans
Parent
commit
92d7db669b

+ 7 - 2
src/main/java/com/its/op/controller/database/TbIfscController.java

@@ -58,10 +58,15 @@ public class TbIfscController {
 
     @ApiOperation(value = "서비스링크개별구성정보조회(TB_IFSC)", response = IfscLinkRltnDto.IfscLinkRltnInfo.class)
     @GetMapping(value = "/link-rltn/{id}", produces = {"application/json; charset=utf8"})
-    public ResponseEntity<IfscLinkRltnDto.IfscLinkRltnInfo> findLinkRltnById(@PathVariable final Long id) {
+    public ResponseEntity<List<IfscLinkRltnDto.IfscLinkRltnInfo>> findLinkRltnById(@PathVariable final Long id) {
         List<IfscLinkRltn> objs = this.service.findLinkRltnById(id);
         if (objs != null) {
-            //return new ResponseEntity<>(new IfscDto.IfscInfo(obj), HttpStatus.OK);
+            List<IfscLinkRltnDto.IfscLinkRltnInfo> result = new ArrayList<>();
+            for (IfscLinkRltn obj : objs) {
+                result.add(new IfscLinkRltnDto.IfscLinkRltnInfo(obj));
+            }
+            log.error("{}", result);
+            return new ResponseEntity<>(result, HttpStatus.OK);
         }
         return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);//NO_CONTENT);
     }

+ 38 - 3
src/main/java/com/its/op/model/dto/IfscLinkRltnDto.java

@@ -1,5 +1,7 @@
 package com.its.op.model.dto;
 
+import com.its.op.global.CodeManager;
+import com.its.op.global.NodeManager;
 import com.its.op.model.entity.IfscLinkRltn;
 import lombok.*;
 
@@ -8,15 +10,48 @@ import java.io.Serializable;
 public class IfscLinkRltnDto implements Serializable {
 
     @Getter
+    @ToString
     public static class IfscLinkRltnInfo {
         private final Long    IFSC_ID;            //	N	NUMBER(10)	    N			정보제공구간 ID
         private final Long    LINK_ID;            //	N	NUMBER(10)	    N			링크 ID
         private final Integer ORD;                //	N	NUMBER(3)	    N			링크 ID
 
+        private final Long    F_NODE_ID;          //	N	NUMBER(10)	    Y			시작노드ID
+        private final Long    T_NODE_ID;          //	N	NUMBER(10)	    Y			종료노드ID
+        private final Integer LANES;              //	N	NUMBER(4)	    Y			차로수
+        private final String  ROAD_RANK;          //	N	VARCHAR2(3)	    Y			도로등급
+        private final String  ROAD_TYPE;          //	N	VARCHAR2(3)	    Y			도로유형
+        private final String  ROAD_NO;            //	N	VARCHAR2(5)	    Y			도로번호
+        private final String  ROAD_NAME;          //	N	VARCHAR2(50)	Y			도로명
+        private final Integer LINK_LENG;          //	N	NUMBER(5)	    Y			연장
+        private final String  SECT_GRAD_CD;       //	N	VARCHAR2(7)	    Y			구간 등급 코드
+
+        private final String FROM_NODE;
+        private final String TO_NODE;
+        private final String ROAD_RANK_DESC;
+        private final String ROAD_TYPE_DESC;
+        private final String SECT_GRAD_CD_DESC;
+
         public IfscLinkRltnInfo(IfscLinkRltn entity) {
-            this.IFSC_ID           = entity.getIFSC_ID();
-            this.LINK_ID           = entity.getLINK_ID();
-            this.ORD               = entity.getORD();
+            this.IFSC_ID      = entity.getIFSC_ID();
+            this.LINK_ID      = entity.getLINK_ID();
+            this.ORD          = entity.getORD();
+            this.F_NODE_ID    = entity.getLink().getF_NODE();
+            this.T_NODE_ID    = entity.getLink().getT_NODE();
+            this.LANES        = entity.getLink().getLANES();
+            this.ROAD_RANK    = entity.getLink().getROAD_RANK();
+            this.ROAD_TYPE    = entity.getLink().getROAD_TYPE();
+            this.ROAD_NO      = entity.getLink().getROAD_NO();
+            this.ROAD_NAME    = entity.getLink().getROAD_NAME();
+            this.LINK_LENG    = entity.getLink().getLINK_LENG();
+            this.SECT_GRAD_CD = entity.getLink().getSECT_GRAD_CD();
+
+            this.FROM_NODE = NodeManager.getNodeName(this.F_NODE_ID);
+            this.TO_NODE = NodeManager.getNodeName(this.T_NODE_ID);
+
+            this.ROAD_RANK_DESC = CodeManager.getCodeDesc(CodeManager.ROAD_RANK, this.ROAD_RANK);
+            this.ROAD_TYPE_DESC = CodeManager.getCodeDesc(CodeManager.ROAD_TYPE, this.ROAD_TYPE);
+            this.SECT_GRAD_CD_DESC = CodeManager.getCodeDesc(CodeManager.SECT_GRAD_CD, this.SECT_GRAD_CD);
         }
     }
 

+ 6 - 6
src/main/java/com/its/op/model/dto/LinkDto.java

@@ -12,8 +12,8 @@ public class LinkDto implements Serializable {
     @Getter
     public static class LinkInfo {
         private final Long    LINK_ID;            //	N	NUMBER(10)	    N			링크ID
-        private final Long    F_NODE;             //	N	NUMBER(10)	    Y			시작노드ID
-        private final Long    T_NODE;             //	N	NUMBER(10)	    Y			종료노드ID
+        private final Long    F_NODE_ID;          //	N	NUMBER(10)	    Y			시작노드ID
+        private final Long    T_NODE_ID;          //	N	NUMBER(10)	    Y			종료노드ID
         private final String  ROAD_USE;           //	N	VARCHAR2(1)	    N			도로사용여부
         private final Integer LANES;              //	N	NUMBER(4)	    Y			차로수
         private final String  ROAD_RANK;          //	N	VARCHAR2(3)	    Y			도로등급
@@ -47,8 +47,8 @@ public class LinkDto implements Serializable {
 
         public LinkInfo(Link entity) {
             this.LINK_ID          = entity.getLINK_ID();
-            this.F_NODE           = entity.getF_NODE();
-            this.T_NODE           = entity.getT_NODE();
+            this.F_NODE_ID        = entity.getF_NODE();
+            this.T_NODE_ID        = entity.getT_NODE();
             this.ROAD_USE         = entity.getROAD_USE();
             this.LANES            = entity.getLANES();
             this.ROAD_RANK        = entity.getROAD_RANK();
@@ -70,8 +70,8 @@ public class LinkDto implements Serializable {
             this.PARA_ID          = entity.getPARA_ID();
             this.DEL_YN           = entity.getDEL_YN();
 
-            this.FROM_NODE = NodeManager.getNodeName(this.F_NODE);
-            this.TO_NODE = NodeManager.getNodeName(this.T_NODE);
+            this.FROM_NODE = NodeManager.getNodeName(this.F_NODE_ID);
+            this.TO_NODE = NodeManager.getNodeName(this.T_NODE_ID);
 
             this.ROAD_USE_DESC = CodeManager.getCodeDesc(CodeManager.ROAD_USE, this.ROAD_USE);
             this.ROAD_RANK_DESC = CodeManager.getCodeDesc(CodeManager.ROAD_RANK, this.ROAD_RANK);

+ 1 - 1
src/main/java/com/its/op/model/entity/CmmnClsfCd.java

@@ -53,6 +53,6 @@ public class CmmnClsfCd implements Serializable {
 /*
     @OneToMany(mappedBy = "cmmnClsfCd", cascade = CascadeType.ALL)//, fetch = FetchType.EAGER)
     //@Fetch(FetchMode.JOIN)
-    private List<CmmnCd> cmmnCds = new ArrayList<>();;*/
+    private List<CmmnCd> cmmnCds = new ArrayList<>();*/
 
 }

+ 9 - 10
src/main/java/com/its/op/model/entity/IfscLinkRltn.java

@@ -6,10 +6,7 @@ import lombok.NoArgsConstructor;
 import org.hibernate.annotations.DynamicInsert;
 import org.hibernate.annotations.DynamicUpdate;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 
 @DynamicInsert
 @DynamicUpdate
@@ -18,15 +15,17 @@ import javax.persistence.Table;
 @AllArgsConstructor
 @Entity
 @Table(name = "TB_IFSC_LINK_RLTN")
+@IdClass(IfscLinkRltnKey.class)
 public class IfscLinkRltn {
 
-    @Id
-    @Column(nullable = false, length = 10)
+    @Id @Column(nullable = false, length = 10)
     private Long    IFSC_ID;            //	N	NUMBER(10)	    N			정보제공구간 ID
-    //@Id
-    @Column(nullable = false, length = 10)
+    @Id @Column(nullable = false, length = 10)
     private Long    LINK_ID;            //	N	NUMBER(10)	    N			링크 ID
-    //@Id
-    @Column(nullable = false, length = 3)
+    @Id @Column(nullable = false, length = 3)
     private Integer ORD;                //	N	NUMBER(3)	    N			링크 ID
+
+    @OneToOne(fetch = FetchType.EAGER)
+    @JoinColumn(insertable=false, updatable=false, name="LINK_ID", referencedColumnName = "LINK_ID")
+    Link link = new Link();
 }

+ 22 - 0
src/main/java/com/its/op/model/entity/IfscLinkRltnKey.java

@@ -0,0 +1,22 @@
+package com.its.op.model.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+//@Embeddable
+public class IfscLinkRltnKey implements Serializable {
+
+    //@Id @Column(nullable = false, length = 10)
+    private Long    IFSC_ID;            //	N	NUMBER(10)	    N			정보제공구간 ID
+    //@Id @Column(nullable = false, length = 10)
+    private Long    LINK_ID;            //	N	NUMBER(10)	    N			링크 ID
+    //@Id @Column(nullable = false, length = 3)
+    private Integer ORD;                //	N	NUMBER(3)	    N			링크 ID
+
+}

+ 3 - 1
src/main/java/com/its/op/repository/IfscLinkRltnRepository.java

@@ -10,6 +10,8 @@ import java.util.List;
 @Repository
 public interface IfscLinkRltnRepository extends JpaRepository<IfscLinkRltn, Long> {
 
-    @Query(value = "select p from IfscLinkRltn p where p.IFSC_ID = ?1")
+    @Query(value = "select distinct p from IfscLinkRltn p inner join fetch p.link where p.IFSC_ID = ?1")
+    //@Query(value = "select p from IfscLinkRltn p where p.IFSC_ID = ?1")
+    //@Query(value = "SELECT distinct t FROM Ifsc t inner join t.from_node inner join t.to_node left outer join fetch t.traf ")
     List<IfscLinkRltn> findLinkRltnById(Long IFSC_ID);
 }