shjung 2 lat temu
rodzic
commit
f869b6993d

+ 4 - 4
src/main/java/com/its/op/dao/repository/its/rse/TbRseObuClctHsRepository.java

@@ -2,7 +2,6 @@ package com.its.op.dao.repository.its.rse;
 
 import com.its.op.entity.its.rse.TbRseObuClctHs;
 import com.its.op.entity.its.rse.TbRseObuClctHsKey;
-import com.its.op.entity.its.rse.TbRseSectTrafHs;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
@@ -21,14 +20,15 @@ public interface TbRseObuClctHsRepository extends JpaRepository<TbRseObuClctHs,
     List<TbRseObuClctHs> findAllList();
 
     @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.obuKind = :kind and p.rseCtlrNmbr in :ids")
-    List<TbRseObuClctHs> findAllCtypByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("kind") String kind, @Param("ids") List<Long> ids);
+    List<TbRseObuClctHs> findAllByObuKindAndDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("kind") String kind, @Param("ids") List<Long> ids);
 
     @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.ctyp = :type and p.rseCtlrNmbr in :ids")
-    List<TbRseObuClctHs> findAllKindByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("type") String type, @Param("ids") List<Long> ids);
+    List<TbRseObuClctHs> findAllByCarTypeAndDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("type") String type, @Param("ids") List<Long> ids);
 
     @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.rseCtlrNmbr in :ids")
     List<TbRseObuClctHs> findAllByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("ids") List<Long> ids);
 
     @Query("select p from TbRseObuClctHs p inner join fetch p.rse where p.clctDt between :fromDt and :toDt and p.ctyp = :type and p.obuKind = :kind and p.rseCtlrNmbr in :ids")
-    List<TbRseObuClctHs> findAllCKByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("type") String type, @Param("kind") String kind, @Param("ids") List<Long> ids);
+    List<TbRseObuClctHs> findAllByCarTypeAndObuKindAndDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("type") String type, @Param("kind") String kind, @Param("ids") List<Long> ids);
+
 }

+ 14 - 44
src/main/java/com/its/op/service/its/rse/TbRseObuClctHsService.java

@@ -3,7 +3,6 @@ package com.its.op.service.its.rse;
 import com.its.op.dao.repository.its.rse.TbRseObuClctHsRepository;
 import com.its.op.dto.its.rse.TbRseObuClctHsDto;
 import com.its.op.entity.its.rse.TbRseObuClctHs;
-import com.its.op.entity.its.rse.TbRseObuClctHsKey;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -11,8 +10,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Optional;
 
 @Slf4j
 @RequiredArgsConstructor
@@ -21,53 +18,25 @@ public class TbRseObuClctHsService {
 
     private final TbRseObuClctHsRepository repo;
 
-    // 데이터 1건 조회, 없으면 exception
-    private TbRseObuClctHs requireOne(TbRseObuClctHsKey id) throws NoSuchElementException {
-        Optional<TbRseObuClctHs> info = this.repo.findById(id);
-        if (info.isPresent()) {
-            return info.get();
-        }
-        else {
-            throw new NoSuchElementException("데이터가 존재하지 않습니다: " + id);
-        }
-//        return this.repo.findById(id)
-//                .orElseThrow(() -> new NoSuchElementException("데이터가 존재하지 않습니다: " + id));
-    }
-
-    // 전체 데이터 조회
-    @Transactional(readOnly = true)
-    public List<TbRseObuClctHsDto> findAll() {
-        List<TbRseObuClctHsDto> result = new ArrayList<>();
-        List<TbRseObuClctHs> data = this.repo.findAll();
-        for (TbRseObuClctHs entity : data) {
-            result.add(entity.toDto());
-        }
-        return result;
-    }
-
-    // 데이터 1건 조회(기존 데이터가 반드시 존재해야 함)
-    @Transactional(readOnly = true)
-    public TbRseObuClctHsDto findById(TbRseObuClctHsKey id) {
-        TbRseObuClctHs entity = requireOne(id);
-        return entity.toDto();
-    }
-
     @Transactional(readOnly = true)
-    public List<TbRseObuClctHsDto> findAllByDateRange(String fromDt, String toDt, String type, String kind, List<Long> ids) {
+    public List<TbRseObuClctHsDto> findAllByDateRange(String fromDt, String toDt, String carType, String obuKind, List<Long> ids) {
         List<TbRseObuClctHsDto> result = new ArrayList<>();
         List<TbRseObuClctHs> data = new ArrayList<>();
-        if (type.equals("00") && !kind.equals("00")) {
-            data = this.repo.findAllCtypByDateRange(fromDt, toDt, kind, ids);
-        }
-        else if (!type.equals("00") && kind.equals("00")) {
-            data = this.repo.findAllKindByDateRange(fromDt, toDt, type, ids);
-        }
-        else if (type.equals("00") && kind.equals("00")) {
-            data = this.repo.findAllByDateRange(fromDt, toDt, ids);
+        if ("ALL".equals(carType)) {
+            if ("ALL".equals(obuKind)) {
+                data = this.repo.findAllByDateRange(fromDt, toDt, ids);
+            } else {
+                data = this.repo.findAllByObuKindAndDateRange(fromDt, toDt, obuKind, ids);
+            }
         }
         else {
-            data = this.repo.findAllCKByDateRange(fromDt, toDt, type, kind, ids);
+            if ("ALL".equals(obuKind)) {
+                data = this.repo.findAllByCarTypeAndDateRange(fromDt, toDt, carType, ids);
+            } else {
+                data = this.repo.findAllByCarTypeAndObuKindAndDateRange(fromDt, toDt, carType, obuKind, ids);
+            }
         }
+
         if (data != null) {
             data.forEach(obj -> {
                 result.add(obj.toDto());
@@ -75,4 +44,5 @@ public class TbRseObuClctHsService {
         }
         return result;
     }
+
 }