|
|
@@ -0,0 +1,91 @@
|
|
|
+package com.its.op.service.vms;
|
|
|
+
|
|
|
+import com.its.op.model.dto.vms.TbVmsSymbIfscDto;
|
|
|
+import com.its.op.model.entity.vms.TbVmsSymbIfsc;
|
|
|
+import com.its.op.model.entity.vms.TbVmsSymbIfscKey;
|
|
|
+import com.its.op.repository.vms.TbVmsSymbIfscRepository;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.NoSuchElementException;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class TbVmsSymbIfscService {
|
|
|
+
|
|
|
+ private final TbVmsSymbIfscRepository repo;
|
|
|
+
|
|
|
+ // 데이터 1건 조회, 없으면 exception
|
|
|
+ private TbVmsSymbIfsc requireOne(TbVmsSymbIfscKey id) {
|
|
|
+ return repo.findById(id)
|
|
|
+ .orElseThrow(() -> new NoSuchElementException("데이터가 존재하지 않습니다: " + id));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 전체 데이터 조회
|
|
|
+ public List<TbVmsSymbIfscDto> findAll() {
|
|
|
+ List<TbVmsSymbIfscDto> result = new ArrayList<>();
|
|
|
+ List<TbVmsSymbIfsc> data = this.repo.findAll();
|
|
|
+ for (TbVmsSymbIfsc entity : data) {
|
|
|
+ result.add(entity.toDto());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 데이터 1건 조회(기존 데이터가 반드시 존재해야 함)
|
|
|
+ public TbVmsSymbIfscDto findById(TbVmsSymbIfscKey id) {
|
|
|
+ TbVmsSymbIfsc entity = requireOne(id);
|
|
|
+ return entity.toDto();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 데이터 변경
|
|
|
+ public TbVmsSymbIfscDto updateById(TbVmsSymbIfscKey id, TbVmsSymbIfscDto.TbVmsSymbIfscUpdReq req) {
|
|
|
+ TbVmsSymbIfsc entity = requireOne(id);
|
|
|
+ entity.updateInfo(req);
|
|
|
+ this.repo.save(entity);
|
|
|
+ return entity.toDto();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 데이터 변경 또는 생성-목록(데이터가 존재하면 업데이트 없으면 신규로 생성)
|
|
|
+ public List<TbVmsSymbIfscDto> mergeInfoList(List<TbVmsSymbIfscDto.TbVmsSymbIfscUpdReq> reqList) {
|
|
|
+ List<TbVmsSymbIfscDto> result = new ArrayList<>();
|
|
|
+ for (TbVmsSymbIfscDto.TbVmsSymbIfscUpdReq req : reqList) {
|
|
|
+ TbVmsSymbIfsc obj = req.toEntity();
|
|
|
+ this.repo.save(obj);
|
|
|
+ result.add(obj.toDto());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 데이터 변경 또는 생성-개별(데이터가 존재하면 업데이트 없으면 신규로 생성)
|
|
|
+ public TbVmsSymbIfscDto mergeInfo(TbVmsSymbIfscDto.TbVmsSymbIfscUpdReq req) {
|
|
|
+ TbVmsSymbIfsc obj = req.toEntity();
|
|
|
+ this.repo.save(obj);
|
|
|
+ return obj.toDto();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 정보 삭제-개별, 데이터 존재하지 않으면 Exception
|
|
|
+ public TbVmsSymbIfscDto deleteById(TbVmsSymbIfscKey id) {
|
|
|
+ TbVmsSymbIfsc entity = requireOne(id);
|
|
|
+ this.repo.deleteById(id);
|
|
|
+ return entity.toDto();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 정보 삭제-목록, 존재하는 데이터 만 삭제
|
|
|
+ public List<TbVmsSymbIfscDto> deleteByIds(List<TbVmsSymbIfscKey> ids) {
|
|
|
+ List<TbVmsSymbIfscDto> result = new ArrayList<>();
|
|
|
+ for (TbVmsSymbIfscKey id : ids) {
|
|
|
+ Optional<TbVmsSymbIfsc> obj = this.repo.findById(id);
|
|
|
+ if (obj.isPresent()) {
|
|
|
+ this.repo.deleteById(id);
|
|
|
+ result.add(obj.get().toDto());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|