| 
					
				 | 
			
			
				@@ -1,9 +1,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.its.op.service.its.cctv; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.op.dao.repository.its.cctv.TbRespCmraMonitoringRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.its.op.dto.its.cctv.TbRespCmraDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.op.dto.its.cctv.TbRespCmraMonitoringDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.its.op.dto.its.common.MonitoringInfoDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.its.op.dto.its.common.MonitoringListDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.its.op.dto.its.common.MonitoringListInf; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.op.entity.its.cctv.TbRespCmraMonitoring; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.its.op.entity.its.cctv.TbRespCmraMonitoringKey; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.RequiredArgsConstructor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -11,8 +14,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 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -20,23 +21,12 @@ import java.util.Optional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class TbRespCmraMonitoringService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final TbRespCmraMonitoringRepository repo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final TbRespCmraService ctlrService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 데이터 1건 조회, 없으면 exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private TbRespCmraMonitoring requireOne(TbRespCmraMonitoringKey id) throws NoSuchElementException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Optional<TbRespCmraMonitoring> 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<TbRespCmraMonitoringDto> findAll() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<TbRespCmraMonitoringDto> findAll(Integer monitoringType) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<TbRespCmraMonitoringDto> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<TbRespCmraMonitoring> data = this.repo.findAll(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (TbRespCmraMonitoring entity : data) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -44,63 +34,108 @@ public class TbRespCmraMonitoringService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 데이터 1건 조회(기존 데이터가 반드시 존재해야 함) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 모니터링 유형에 속한 모든 데이터 조회 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional(readOnly = true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public TbRespCmraMonitoringDto findById(TbRespCmraMonitoringKey id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        TbRespCmraMonitoring entity = requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return entity.toDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<TbRespCmraMonitoringDto> findAllMonitoring(Integer monitoringType) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TbRespCmraMonitoringDto> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TbRespCmraMonitoring> data = this.repo.findAllMonitoring(monitoringType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (data != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data.forEach(obj -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                result.add(obj.toDto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 데이터 변경 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public TbRespCmraMonitoringDto updateById(TbRespCmraMonitoringKey id, TbRespCmraMonitoringDto.TbRespCmraMonitoringUpdReq req) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        TbRespCmraMonitoring entity = requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        entity.updateInfo(req); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        this.repo.save(entity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return entity.toDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 모니터링 이름으로 모니터링목록 조회 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional(readOnly = true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<TbRespCmraMonitoringDto> findByName(Integer monitoringType, String name) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 데이터 변경 또는 생성-목록(데이터가 존재하면 업데이트 없으면 신규로 생성) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public List<TbRespCmraMonitoringDto> mergeInfoList(List<TbRespCmraMonitoringDto.TbRespCmraMonitoringUpdReq> reqList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //	모니터링유형(1:예비,2,예비,3,영상,4:예비) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<TbRespCmraMonitoringDto> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for (TbRespCmraMonitoringDto.TbRespCmraMonitoringUpdReq req : reqList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            TbRespCmraMonitoring obj = req.toEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            this.repo.save(obj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            result.add(obj.toDto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TbRespCmraMonitoring> data = this.repo.findByName(monitoringType, name.trim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (data != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data.forEach(obj -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                result.add(obj.toDto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 데이터 변경 또는 생성-개별(데이터가 존재하면 업데이트 없으면 신규로 생성) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public TbRespCmraMonitoringDto mergeInfo(TbRespCmraMonitoringDto.TbRespCmraMonitoringUpdReq req) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        TbRespCmraMonitoring obj = req.toEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        this.repo.save(obj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return obj.toDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<TbRespCmraMonitoringDto> mergeInfo(Integer monitoringType, String name, TbRespCmraMonitoringDto.TbRespCmraMonitoringUpdReq req) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // Repository 에서 Transaction 처리를 수행 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 이름에 해당하는 데이터 삭제 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.repo.deleteByName(monitoringType, req.getOrgMonitoringNm().trim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 이름에 해당하는 모든 데이터 저장 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (MonitoringInfoDto reqObj : req.getInfos()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            TbRespCmraMonitoring obj = TbRespCmraMonitoring.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .monitoringType(monitoringType) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .monitoringNm(name.trim()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .monitoringSeq(reqObj.getMonitoringSeq()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .respCmraNmbr(reqObj.getCtlrNmbr()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            obj.setType(monitoringType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.repo.save(obj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 저장된 데이터 리턴 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return findByName(monitoringType, name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 정보 삭제-개별, 데이터 존재하지 않으면 Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public TbRespCmraMonitoringDto deleteById(TbRespCmraMonitoringKey id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        TbRespCmraMonitoring entity = requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        this.repo.deleteById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return entity.toDto(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<TbRespCmraMonitoringDto> deleteByName(Integer monitoringType, String name) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TbRespCmraMonitoringDto> result = findByName(monitoringType, name.trim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (result != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.repo.deleteByName(monitoringType, name.trim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 정보 삭제-목록, 존재하는 데이터 만 삭제 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public List<TbRespCmraMonitoringDto> deleteByIds(List<TbRespCmraMonitoringKey> ids) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<TbRespCmraMonitoringDto> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for (TbRespCmraMonitoringKey id : ids) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Optional<TbRespCmraMonitoring> obj = this.repo.findById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (obj.isPresent()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                this.repo.deleteById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                result.add(obj.get().toDto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 모니터링 화면 리스트 소회 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param monitoringType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public List<MonitoringListDto> findAllMonitoringList(Integer monitoringType) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<MonitoringListDto> result = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<MonitoringListInf> data = this.repo.findAllMonitoringList(monitoringType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data.forEach(obj -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            result.add(MonitoringListDto.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .monitoringType(monitoringType) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .monitoringNm(obj.getName().trim()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .count(obj.getCount().intValue()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .build()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (result.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 모니터링 화면이 없으면 Default 화면 목록을 만든다 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<TbRespCmraDto> ctlrList = this.ctlrService.findAllList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int seq = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (int ii = 0; ii < ctlrList.size(); ii++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                TbRespCmraDto obj = ctlrList.get(ii); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                TbRespCmraMonitoring entity = TbRespCmraMonitoring.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .monitoringType(monitoringType) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .monitoringNm("Default") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .monitoringSeq(seq++) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .respCmraNmbr(obj.getRespCmraNmbr()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                this.repo.save(entity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (seq == 16) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            result.add(MonitoringListDto.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .monitoringType(monitoringType) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .monitoringNm("Default") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .count(seq) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .build()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |