| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package com.its.op.service.cctv;
- import com.its.op.model.dto.cctv.CctvMonitoringDto;
- import com.its.op.model.entity.cctv.CctvMonitoring;
- import com.its.op.repository.cctv.CctvMonitoringRepository;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import javax.transaction.Transactional;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- @Slf4j
- @RequiredArgsConstructor
- @Service
- public class TbCctvMonitoringService {
- private final CctvMonitoringRepository repo;
- public List<CctvMonitoring> findAll() {
- try {
- return this.repo.findAll();
- }
- catch (Exception e) {
- log.error("{}.findAll: Exception: {}", getClass().getSimpleName(), e.getMessage());
- }
- return new ArrayList<CctvMonitoring>();
- }
- public List<CctvMonitoring> findByName(String name) {
- try {
- return this.repo.findByName(name);
- }
- catch (Exception e) {
- log.error("{}.findByName: Object: {}, Exception: {}", getClass().getSimpleName(), name, e.getMessage());
- }
- return new ArrayList<CctvMonitoring>();
- }
- @Transactional
- public List<CctvMonitoringDto.CctvMonitoringUpdateReq> mergeInfo(List<CctvMonitoringDto.CctvMonitoringUpdateReq> req) {
- try {
- HashSet<String> names = new HashSet<String>();
- for (CctvMonitoringDto.CctvMonitoringUpdateReq obj : req) {
- names.add(obj.getMONITORING_NM());
- }
- for (String name : names) {
- this.repo.deleteByName(name);
- }
- //this.repo.flush();
- for (CctvMonitoringDto.CctvMonitoringUpdateReq obj : req) {
- CctvMonitoring data = new CctvMonitoring(3, obj);
- //this.repo.save(data);
- this.repo.insertValue(data.getMONITORING_TYPE(),
- data.getMONITORING_NM(),
- data.getMONITORING_SEQ(),
- data.getCCTV_CTLR_NMBR(),
- data.getVIEW_MODE());
- }
- return req;
- }
- catch (Exception e) {
- log.error("{}.mergeInfo: Object: {}, Exception: {}", getClass().getSimpleName(), req, e.getMessage());
- }
- return null;
- }
- @Transactional
- public List<CctvMonitoring> deleteByName(String name) {
- try {
- List<CctvMonitoring> result = this.repo.findByName(name);
- if (result != null && result.size() > 0) {
- this.repo.deleteByName(name);
- }
- return result;
- }
- catch (Exception e) {
- log.error("{}.deleteByName: Object: {}, Exception: {}", getClass().getSimpleName(), name, e.getMessage());
- }
- return new ArrayList<CctvMonitoring>();
- }
- }
|