瀏覽代碼

report mapper to jpa

shjung 3 年之前
父節點
當前提交
f827400868

+ 11 - 0
src/main/java/com/its/api/its/controller/report/ReportController.java

@@ -36,6 +36,17 @@ public class ReportController {
 
         return this.service.findAllFacilitySummary(FROM_DT, TO_DT);
     }
+/*
+    @ApiOperation(value = "시설물보고서-시설물 현황", response = ReportFacilitySummaryDto.class, responseContainer = "ArrayList")
+    @GetMapping(value = "/facility/summary2", produces = {"application/json; charset=utf8"})
+    public List<ReportFacilitySummaryDto> findAllFacilitySummary2(
+            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24MI00)", example = "20220327000000", required = true)
+            @RequestParam String FROM_DT,
+            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24MI59)", example = "20220327235959", required = true)
+            @RequestParam String TO_DT) {
+
+        return this.service.findAllReportFacilitySummary(FROM_DT, TO_DT);
+    }*/
 
     @ApiOperation(value = "시설물보고서-장애 현황", response = ReportFacilityErrorDto.class, responseContainer = "ArrayList")
     @GetMapping(value = "/facility/error", produces = {"application/json; charset=utf8"})

+ 5 - 5
src/main/java/com/its/api/its/model/dto/report/ReportFacilityErrorDto.java

@@ -18,17 +18,17 @@ import java.io.Serializable;
 public class ReportFacilityErrorDto  implements Serializable {
     @ApiModelProperty("일련번호")
     @JsonProperty("fclt_seq")
-    private int    FCLT_SEQ;
+    private int fcltSeq;
     @ApiModelProperty("시설물유형")
     @JsonProperty("fclt_type")
-    private String FCLT_TYPE;
+    private String fcltType;
     @ApiModelProperty("시설물 ID")
     @JsonProperty("fclt_id")
-    private String FCLT_ID;
+    private String fcltId;
     @ApiModelProperty("시설물명")
     @JsonProperty("fclt_nm")
-    private String FCLT_NM;
+    private String fcltNm;
     @ApiModelProperty("등록시각")
     @JsonProperty("rgst_dt")
-    private String RGST_DT;
+    private String rgstDt;
 }

+ 4 - 4
src/main/java/com/its/api/its/model/dto/report/ReportFacilitySummaryDto.java

@@ -15,14 +15,14 @@ import java.io.Serializable;
 public class ReportFacilitySummaryDto  implements Serializable {
     @ApiModelProperty("일련번호")
     @JsonProperty("fclt_seq")
-    private int    FCLT_SEQ;
+    private int fcltSeq;
     @ApiModelProperty("시설물 유형")
     @JsonProperty("fclt_type")
-    private String FCLT_TYPE;
+    private String fcltType;
     @ApiModelProperty("정상건수")
     @JsonProperty("cms0_cnt")
-    private int    CMS0_CNT;
+    private int cms0Cnt;
     @ApiModelProperty("장애건수")
     @JsonProperty("cms1_cnt")
-    private int    CMS1_CNT;
+    private int cms1Cnt;
 }

+ 13 - 0
src/main/java/com/its/api/its/model/dto/report/ReportFcltSummaryInf.java

@@ -0,0 +1,13 @@
+package com.its.api.its.model.dto.report;
+
+import java.math.BigDecimal;
+
+/**
+ * 보고서 시설물 현황 Interface Class
+ */
+public interface ReportFcltSummaryInf {
+
+    BigDecimal getCms0Cnt();
+    BigDecimal getCms1Cnt();
+
+}

+ 16 - 0
src/main/java/com/its/api/its/repository/cctv/TbCctvSttsHsRepository.java

@@ -1,6 +1,7 @@
 package com.its.api.its.repository.cctv;
 
 import com.its.api.its.model.dto.common.SttsHsErrCntInf;
+import com.its.api.its.model.dto.report.ReportFcltSummaryInf;
 import com.its.api.its.model.entity.cctv.TbCctvSttsHs;
 import com.its.api.its.model.entity.cctv.TbCctvSttsHsKey;
 import org.springframework.data.jpa.repository.JpaRepository;
@@ -28,4 +29,19 @@ public interface TbCctvSttsHsRepository extends JpaRepository<TbCctvSttsHs, TbCc
            "   and p.cmncSttsCd <> 'CMS0' " +
            "   and p.cctvMngmNmbr in :ids")
     List<TbCctvSttsHs> findAllFailByDateRange(String fromDt, String toDt, List<Long> ids);
+
+    @Query(value =
+            "SELECT NVL(SUM(CMS0CNT), 0) AS cms0Cnt, NVL(SUM(CMS1CNT), 0) AS cms1Cnt " +
+                    "  FROM (SELECT DECODE(CMNC_STTS_CD, 'CMS0', 1, 0) AS CMS0CNT, " +
+                    "               DECODE(CMNC_STTS_CD, 'CMS0', 0, 1) AS CMS1CNT  " +
+                    "          FROM TB_CCTV_STTS_HS " +
+                    "         WHERE CRTN_DT BETWEEN :fromDt AND :toDt" +
+                    "       )", nativeQuery = true)
+    ReportFcltSummaryInf findAllReportSummary(String fromDt, String toDt);
+
+    @Query("select p from TbCctvSttsHs p inner join fetch p.cctv " +
+            " where p.crtnDt between :fromDt and :toDt " +
+            "   and p.cmncSttsCd = 'CMS1' ")
+    List<TbCctvSttsHs> findAllReportError(String fromDt, String toDt);
+
 }

+ 0 - 5
src/main/java/com/its/api/its/repository/report/ReportMapper.java

@@ -1,7 +1,5 @@
 package com.its.api.its.repository.report;
 
-import com.its.api.its.model.dto.report.ReportFacilityErrorDto;
-import com.its.api.its.model.dto.report.ReportFacilitySummaryDto;
 import com.its.api.its.model.dto.report.ReportTrafficCongestDto;
 import com.its.api.its.model.dto.report.ReportTrafficIncidentDto;
 import org.apache.ibatis.annotations.Mapper;
@@ -12,9 +10,6 @@ import java.util.Map;
 @Mapper
 public interface ReportMapper {
 
-    List<ReportFacilitySummaryDto> findAllFacilitySummary(Map<String, String> param);
-    List<ReportFacilityErrorDto> findAllFacilityError(Map<String, String> param);
-
     List<ReportTrafficIncidentDto> findAllTrafficIncident(Map<String, String> param);
     List<ReportTrafficCongestDto> findAllTrafficCongest(Map<String, String> param);
 

+ 15 - 0
src/main/java/com/its/api/its/repository/vds/TbVdsCtlrSttsHsRepository.java

@@ -1,6 +1,7 @@
 package com.its.api.its.repository.vds;
 
 import com.its.api.its.model.dto.common.SttsHsErrCntInf;
+import com.its.api.its.model.dto.report.ReportFcltSummaryInf;
 import com.its.api.its.model.entity.vds.TbVdsCtlrSttsHs;
 import com.its.api.its.model.entity.vds.TbVdsCtlrSttsHsKey;
 import org.springframework.data.jpa.repository.JpaRepository;
@@ -28,4 +29,18 @@ public interface TbVdsCtlrSttsHsRepository extends JpaRepository<TbVdsCtlrSttsHs
            "   and (p.cmncSttsCd <> 'CMS0' or p.cboxDoorSttsCd <> 'CDS0' or p.cboxTmpr > 40)" +
            "   and p.ctlrMngmNmbr in :ids")
     List<TbVdsCtlrSttsHs> findAllFailByDateRange(String fromDt, String toDt, List<String> ids);
+
+    @Query(value =
+            "SELECT NVL(SUM(CMS0CNT), 0) AS cms0Cnt, NVL(SUM(CMS1CNT), 0) AS cms1Cnt " +
+                    "  FROM (SELECT DECODE(CMNC_STTS_CD, 'CMS0', 1, 0) AS CMS0CNT, " +
+                    "               DECODE(CMNC_STTS_CD, 'CMS0', 0, 1) AS CMS1CNT  " +
+                    "          FROM TB_VDS_CTLR_STTS_RAW " +
+                    "         WHERE OCRR_DT BETWEEN :fromDt AND :toDt" +
+                    "       )", nativeQuery = true)
+    ReportFcltSummaryInf findAllReportSummary(String fromDt, String toDt);
+
+    @Query("select p from TbVdsCtlrSttsHs p inner join fetch p.vds " +
+            " where p.ocrrDt between :fromDt and :toDt " +
+            "   and p.cmncSttsCd = 'CMS1' ")
+    List<TbVdsCtlrSttsHs> findAllReportError(String fromDt, String toDt);
 }

+ 17 - 0
src/main/java/com/its/api/its/repository/vms/TbVmsSttsHsRepository.java

@@ -1,6 +1,7 @@
 package com.its.api.its.repository.vms;
 
 import com.its.api.its.model.dto.common.SttsHsErrCntInf;
+import com.its.api.its.model.dto.report.ReportFcltSummaryInf;
 import com.its.api.its.model.entity.vms.TbVmsSttsHs;
 import com.its.api.its.model.entity.vms.TbVmsSttsHsKey;
 import org.springframework.data.jpa.repository.JpaRepository;
@@ -28,4 +29,20 @@ public interface TbVmsSttsHsRepository extends JpaRepository<TbVmsSttsHs, TbVmsS
            "   and (p.connSttsCd <> 'CMS0' or p.cboxdoorOpenSttsCd <> 'CDS0' or p.cboxTmpr > 40)" +
            "   and p.vmsCtlrNmbr in :ids")
     List<TbVmsSttsHs> findAllFailByDateRange(String fromDt, String toDt, List<Long> ids);
+
+    @Query(value =
+            "SELECT NVL(SUM(CMS0CNT), 0) AS cms0Cnt, NVL(SUM(CMS1CNT), 0) AS cms1Cnt " +
+            "  FROM (SELECT DECODE(CONN_STTS_CD, 'CMS0', 1, 0) AS CMS0CNT, " +
+            "               DECODE(CONN_STTS_CD, 'CMS0', 0, 1) AS CMS1CNT  " +
+            "          FROM TB_VMS_STTS_HS " +
+            "         WHERE RGST_DT BETWEEN :fromDt AND :toDt" +
+            "       )", nativeQuery = true)
+    ReportFcltSummaryInf findAllReportSummary(String fromDt, String toDt);
+
+
+    @Query("select p from TbVmsSttsHs p inner join fetch p.vms " +
+            " where p.rgstDt between :fromDt and :toDt " +
+            "   and p.connSttsCd = 'CMS1' ")
+    List<TbVmsSttsHs> findAllReportError(String fromDt, String toDt);
+
 }

+ 84 - 12
src/main/java/com/its/api/its/service/report/ReportService.java

@@ -1,14 +1,19 @@
 package com.its.api.its.service.report;
 
-import com.its.api.its.model.dto.report.ReportFacilityErrorDto;
-import com.its.api.its.model.dto.report.ReportFacilitySummaryDto;
-import com.its.api.its.model.dto.report.ReportTrafficCongestDto;
-import com.its.api.its.model.dto.report.ReportTrafficIncidentDto;
+import com.its.api.its.model.dto.report.*;
+import com.its.api.its.model.entity.cctv.TbCctvSttsHs;
+import com.its.api.its.model.entity.vds.TbVdsCtlrSttsHs;
+import com.its.api.its.model.entity.vms.TbVmsSttsHs;
+import com.its.api.its.repository.cctv.TbCctvSttsHsRepository;
 import com.its.api.its.repository.report.ReportMapper;
+import com.its.api.its.repository.vds.TbVdsCtlrSttsHsRepository;
+import com.its.api.its.repository.vms.TbVmsSttsHsRepository;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -19,19 +24,86 @@ import java.util.Map;
 public class ReportService {
 
     private final ReportMapper mapper;
+    private final TbCctvSttsHsRepository cctvSttsHsRepo;
+    private final TbVmsSttsHsRepository vmsSttsHsRepo;
+    private final TbVdsCtlrSttsHsRepository vdsSttsHsRepo;
 
+    /**
+     * 보고서 - 시설물 보고서 - 시설물 현황
+     * @param fromDt
+     * @param toDt
+     * @return
+     */
+    @Transactional(readOnly = true)
     public List<ReportFacilitySummaryDto> findAllFacilitySummary(String fromDt, String toDt){
-        Map<String, String> param = new HashMap<>();
-        param.put("FROM_DT", fromDt);
-        param.put("TO_DT", toDt);
-        return this.mapper.findAllFacilitySummary(param);
+
+        List<ReportFacilitySummaryDto> result = new ArrayList<>();
+
+        ReportFcltSummaryInf cctvSummary = this.cctvSttsHsRepo.findAllReportSummary(fromDt, toDt);
+        result.add(ReportFacilitySummaryDto.builder()
+                .fcltSeq(1)
+                .fcltType("CCTV")
+                .cms0Cnt(cctvSummary.getCms0Cnt().intValue())
+                .cms1Cnt(cctvSummary.getCms1Cnt().intValue())
+                .build());
+
+        ReportFcltSummaryInf vmsSummary = this.vmsSttsHsRepo.findAllReportSummary(fromDt, toDt);
+        result.add(ReportFacilitySummaryDto.builder()
+                .fcltSeq(2)
+                .fcltType("VMS")
+                .cms0Cnt(vmsSummary.getCms0Cnt().intValue())
+                .cms1Cnt(vmsSummary.getCms1Cnt().intValue())
+                .build());
+
+        ReportFcltSummaryInf vdsSummary = this.vdsSttsHsRepo.findAllReportSummary(fromDt, toDt);
+        result.add(ReportFacilitySummaryDto.builder()
+                .fcltSeq(3)
+                .fcltType("VDS")
+                .cms0Cnt(vdsSummary.getCms0Cnt().intValue())
+                .cms1Cnt(vdsSummary.getCms1Cnt().intValue())
+                .build());
+
+        return result;
     }
 
     public List<ReportFacilityErrorDto> findAllFacilityError(String fromDt, String toDt){
-        Map<String, String> param = new HashMap<>();
-        param.put("FROM_DT", fromDt);
-        param.put("TO_DT", toDt);
-        return this.mapper.findAllFacilityError(param);
+
+        List<ReportFacilityErrorDto> result = new ArrayList<>();
+
+        List<TbCctvSttsHs> cctvError = this.cctvSttsHsRepo.findAllReportError(fromDt, toDt);
+        cctvError.forEach(obj -> {
+            result.add(ReportFacilityErrorDto.builder()
+                    .fcltSeq(1)
+                    .fcltType("CCTV")
+                    .fcltId(obj.getCctv() != null ? obj.getCctv().getCctvCtlrId() : String.valueOf(obj.getCctvMngmNmbr()))
+                    .fcltNm(obj.getCctv() != null ? obj.getCctv().getIstlLctnNm() : String.valueOf(obj.getCctvMngmNmbr()))
+                    .rgstDt(obj.getCrtnDt())
+                    .build());
+        });
+
+
+        List<TbVmsSttsHs>  vmsError = this.vmsSttsHsRepo.findAllReportError(fromDt, toDt);
+        vmsError.forEach(obj -> {
+            result.add(ReportFacilityErrorDto.builder()
+                    .fcltSeq(2)
+                    .fcltType("VMS")
+                    .fcltId(obj.getVms() != null ? obj.getVms().getVmsCtlrId() : String.valueOf(obj.getVmsCtlrNmbr()))
+                    .fcltNm(obj.getVms() != null ? obj.getVms().getVmsNm() : String.valueOf(obj.getVmsCtlrNmbr()))
+                    .rgstDt(obj.getRgstDt()).build());
+        });
+
+        List<TbVdsCtlrSttsHs>  vdsError = this.vdsSttsHsRepo.findAllReportError(fromDt, toDt);
+        vdsError.forEach(obj -> {
+            result.add(ReportFacilityErrorDto.builder()
+                    .fcltSeq(3)
+                    .fcltType("VDS")
+                    .fcltId(obj.getVds() != null ? obj.getVds().getVdsCtlrId() : obj.getCtlrMngmNmbr())
+                    .fcltNm(obj.getVds() != null ? obj.getVds().getLctn() : obj.getCtlrMngmNmbr())
+                    .rgstDt(obj.getOcrrDt())
+                    .build());
+        });
+
+        return result;
     }
 
     public List<ReportTrafficIncidentDto> findAllTrafficIncident(String fromDt, String toDt){

+ 0 - 63
src/main/resources/mybatis/mapper/report/ReportMapper.xml

@@ -3,69 +3,6 @@
 
 <mapper namespace="com.its.api.its.repository.report.ReportMapper">
 
-    <select id="findAllFacilitySummary" parameterType="java.util.HashMap" resultType="com.its.api.its.model.dto.report.ReportFacilitySummaryDto">
-       <![CDATA[
-        SELECT FACSEQ AS FCLT_SEQ, FACTYPE AS FCLT_TYPE, NVL(CMS0CNT, 0) AS CMS0_CNT, NVL(CMS1CNT, 0) AS CMS1_CNT
-        FROM (SELECT 1 as FACSEQ, 'CCTV' AS FACTYPE, SUM(CMS0CNT)AS CMS0CNT, SUM(CMS1CNT) AS CMS1CNT
-                FROM (SELECT DECODE(CMNC_STTS_CD, 'CMS0', 1, 0) AS CMS0CNT,
-                             DECODE(CMNC_STTS_CD, 'CMS0', 0, 1) AS CMS1CNT
-                        FROM TB_CCTV_STTS_HS
-                       WHERE CRTN_DT BETWEEN #{FROM_DT} AND #{TO_DT}
-                      )
-              UNION
-              SELECT 2 as FACSEQ, 'VMS' AS FACTYPE, SUM(CMS0CNT)AS CMS0CNT, SUM(CMS1CNT) AS CMS1CNT
-              FROM (SELECT DECODE(CONN_STTS_CD, 'CMS0', 1, 0) AS CMS0CNT,
-                           DECODE(CONN_STTS_CD, 'CMS0', 0, 1) AS CMS1CNT
-                    FROM TB_VMS_STTS_HS
-                    WHERE RGST_DT BETWEEN #{FROM_DT} AND #{TO_DT}
-                   )
-              UNION
-              SELECT 3 as FACSEQ, 'VDS' AS FACTYPE, SUM(CMS0CNT) AS CMS0CNT, SUM(CMS1CNT) AS CMS1CNT
-              FROM (SELECT DECODE(CMNC_STTS_CD, 'CMS0', 1, 0) AS CMS0CNT,
-                           DECODE(CMNC_STTS_CD, 'CMS0', 0, 1) AS CMS1CNT
-                    FROM TB_VDS_CTLR_STTS_RAW
-                    WHERE OCRR_DT BETWEEN #{FROM_DT} AND #{TO_DT}
-                   )
-             )
-        ORDER BY FACSEQ
-        ]]>
-    </select>
-
-    <select id="findAllFacilityError" parameterType="java.util.HashMap" resultType="com.its.api.its.model.dto.report.ReportFacilityErrorDto">
-       <![CDATA[
-        SELECT FACSEQ AS FCLT_SEQ, FCLT_TYPE, FCLT_ID, FCLT_NM, RGST_DT
-        FROM (
-                 SELECT 1 as FACSEQ, 'CCTV' FCLT_TYPE, A.CCTV_CTLR_ID AS FCLT_ID, A.ISTL_LCTN_NM AS FCLT_NM,
-                        CRTN_DT AS RGST_DT
-                 FROM TB_CCTV_CTLR A,
-                      (SELECT CCTV_MNGM_NMBR, CRTN_DT
-                       FROM TB_CCTV_STTS_HS
-                       WHERE CRTN_DT BETWEEN #{FROM_DT} AND #{TO_DT}
-                         AND CMNC_STTS_CD = 'CMS1') B
-                 WHERE A.CCTV_MNGM_NMBR = B.CCTV_MNGM_NMBR
-                 UNION
-                 SELECT 2 as FACSEQ, 'VMS' FCLT_TYPE, A.VMS_CTLR_ID AS FCLT_ID, A.VMS_NM AS FCLT_NM,
-                        RGST_DT AS RGST_DT
-                 FROM TB_VMS_CTLR A,
-                      (SELECT VMS_CTLR_NMBR, RGST_DT
-                       FROM TB_VMS_STTS_HS
-                       WHERE RGST_DT BETWEEN #{FROM_DT} AND #{TO_DT}
-                         AND CONN_STTS_CD = 'CMS1') B
-                 WHERE A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR
-                 UNION
-                 SELECT 3 as FACSEQ, 'VDS' FCLT_TYPE, A.CTLR_MNGM_NMBR AS FCLT_ID, A.LCTN AS FCLT_NM,
-                        OCRR_DT AS RGST_DT
-                 FROM TB_VDS_CTLR A,
-                      (SELECT CTLR_MNGM_NMBR, OCRR_DT
-                       FROM TB_VDS_CTLR_STTS_RAW
-                       WHERE OCRR_DT BETWEEN #{FROM_DT} AND #{TO_DT}
-                         AND CMNC_STTS_CD = 'CMS1') B
-                 WHERE A.CTLR_MNGM_NMBR = B.CTLR_MNGM_NMBR
-             )
-        ORDER BY FACSEQ, FCLT_ID, RGST_DT
-        ]]>
-    </select>
-
     <select id="findAllTrafficIncident" parameterType="java.util.HashMap" resultType="com.its.api.its.model.dto.report.ReportTrafficIncidentDto">
        <![CDATA[
         SELECT INCD_STRT_DT, B.CMMN_CD_KOR_NM, LINK_ID, INCD_TITL